• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Load Property file in servlet or jsp

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Here is the directory structure as per eclipse: -

Project:-


SWA_JSP
|
|-----src
| |
| |---org.omkar.swa.resources (package)
| | |
| | |----login.properties
| |
| |---org.omkar.swa.servlets
| | |
| | |----LoginServlet.java
| |
| |---org.omkar.swa.test
| | |
| | |----Tester.java
|
|
|-----WebContent
| |
| |---login.jsp



Now, as per the above structure, ... my problem is to load the login.properties file in the init() method of the LoginServlet.java ...since i need some parameters from the property file. My problem is, i am not able to load the file when i run the server,....i have placed following code in the init() method: -



the value of inputStream is null, ... however, if i run this piece of code in the Tester.java which is a simple void main standalone class,....it runs perfectly well!!!...the property file gets loaded!!! ... Why the difference ?

How do i load the property file, when running the server ?

Thanks and Regards
Omkar Patkar
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like a path problem. Is the path looked at by the ClassLoader the one you think it is? Is there a package path involved?
There is the relative path from where the package path puts you and an absolute path from the current directory.
See the doc for Class.getResourceAsStream() for description.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Norm,

Thanks for the reply,...my problem is solved now,.. ..there was path problem...i made following changes: -


and the property file is loaded, .... but i did not understand the following line from your reply: -

Is there a package path involved?
There is the relative path from where the package path puts you and an absolute path from the current directory.



what is package path, relative path and absolute path ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic