Servlet Resources

Servlet Resources

Where is the best place to store .property files and .xml files for servlets/jsp? Right now I am using “user.home”, but there is a problem when you have multiple web application because you may store only one set of files.

You have several choices. You could use resource bundles, store the files in the classpath and use Class.getResource() to retrieve it, use servlet init parameters to tell the servlet the location of the resources, or define system properties.

Resource bundles are the most general mechanism and allow for internationalization. Servlet initparameters allow the greatest flexibility in that you can pass any arbitrary location to the servlet. Storing files in the classpath makes for rather awkward applicaiton deployments as does defining system properties. Ultimately, the exact nature of your application will dictate the most appropriate way to go.


Share the Post: