Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Load Property file in servlet or jsp  RSS feed

 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!