• 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

Unable to access config files from a servlet

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have kept my logger configuration file[config.properties] at /WEB-INF/config folder.But iam unable to read the file from my servlet class. In my servlet iam trying to read the file using path '/WEB-INF/config/config.properties'. Have i placed the file at the right location ? Would it be included in the classpath? Thanks in advance.
Nadda
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us the code you're using to read the config file.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Would it be included in the classpath?


If you mean the CLASSPATH environment setting, servlet containers generally ignore it. Servlet containers also ignore the "current" directory.

Your problem is probably related to the difference between the way the server "sees" application relative paths and the way the operating system sees absolute paths. If you are trying to read a file using typical java.io.File related methods, you need absolute paths.

Bill
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nadda,
Normally when you use ResourceBundle or Properties file, server doent look inside the classes folder.

To access any file you need to get the entire path of the file.

For eg:-
If you have created your project inside d:/project/pro1

Then the entire path is d:/project/proc1/WEB-INF/config/config.properties


To do that,
ServletContext context = servletConfig.getServletContext();
String strPath = context.getRealPath("/WEB-INF/config/config.properties");

You can pass this strPath to load your configuration file.

Regards,
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by balakrishnan periysawamy:
Normally when you use ResourceBundle or Properties file, server doent look inside the classes folder.

To access any file you need to get the entire path of the file.



This is misleading. Firstly, it depends on whether you want your reference as a File, URL or Stream. If you decide to package code as a library, it makes sense to use the ClassLoader to find resources attached to your code.

If you package as a web application, you may decide to refer to resources relative to the context root, but from experience I prefer to refer to web resources by URL or Stream, since you cannot get an absloute File reference when it is packaged in a WAR file.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic