How do you access application root static pages or WEB-INF jars in a non-servlet clas

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishna81m
    New Member
    • Oct 2007
    • 25

    #1

    How do you access application root static pages or WEB-INF jars in a non-servlet clas

    In a general servlet class after deployment, you can access the application root as servletContext. getRealPath("/") to access any of the properties files in the "WEB-INF" directory or anywhere else in the /webapp-root/ directory.

    How can we get the equivalent servletContext. getRealPath("/") in a non-servlet where you are interested to access a property file located in "/webapp-root/WEB-INF" or probably a text file stored in a static folder pages in the /webapp-root/pages/ folder.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Originally posted by krishna81m
    In a general servlet class after deployment, you can access the application root as servletContext. getRealPath("/") to access any of the properties files in the "WEB-INF" directory or anywhere else in the /webapp-root/ directory.

    How can we get the equivalent servletContext. getRealPath("/") in a non-servlet where you are interested to access a property file located in "/webapp-root/WEB-INF" or probably a text file stored in a static folder pages in the /webapp-root/pages/ folder.
    1.) dynamic read
    get the windows environment variable for the webserver directory (e.g tomcat) and add ""/webapp-root/WEB-INF" to it. (or parse the tomcat configuration file where you have mapped the web-directory to a real path on your harddisk )

    2.) hardcode read
    - or you can just make a configuration file, which will be read from your non-servlet program, and put the whole path there inside,
    - or you can pass the folder as a parameter to java when you start your non-servlet program
    - or you can set thepath inside a (windows) environment variable and read it from there.

    3.) database read
    store the path inside a database table when you run the servlet. Then read this path when you run your non-servlet app.

    4.) remote read:
    use RMI, Corba or other ways (Sockets, pipes, shared memory) to pass the
    path from one program to another.

    Comment

    • krishna81m
      New Member
      • Oct 2007
      • 25

      #3
      I ended up hard coding.. I hate this.

      Wish someone could teach me how to use context listener to initialize the variable as string from a servlet's servletContext( ) method and save to application scope and then be able to access this?

      Or pass servletContext object itself to the non-servlet.

      Help requested.

      Comment

      Working...