devxlogo

Servlet Resources

Servlet Resources

Question:
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.

Answer:
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.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist