• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

context path in java class

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

i am using servlets and jsp's for my web application... through servlet i am calling a java class and that class reads a property file.. when i am working on eclipse i gave the absolute path for the file.. but after deploying the class is unable to retrieve the exact path... someone please help me how to give a file location in web context (this file is read by a normal java class.. not a servlet or jsp)
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Avinash,

In servlet you are calling a java class means at the top, you should have written import statement for that class. Then in that case there should not be any problem after deploying the class... Can you please share some line of code so that we can investigate it ?

Thanks

Rahul
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Always use paths that are relative to the context root of the web app. That way you can ensure that your class gets the desired resources.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use the getResourceAsStream() method of the ServletContext to read the properties file as stream. I am assuming your properties file is not outside the web application

Since your are reading the properties file in a non servlet class, get the stream in a servlet and pass the InputStream to your java class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic