I have to use a xml file from file system, for example, a file with the name of treeview.xml, located in the WEB-INF/classes/com/yahoo/resources/, and I need to use that in a class of web layer. how cannot I get the path of that file? later, I was wondering if I can write the path into the web.xml as a parameter. but how to use it in a class? poor knowledge about this. pls help me. any word is apprieciable.
You can read a file from the WEB-INF directory of your application with something like:
where config is the ServletConfig, surveys is a directory under WEB-INF and survey.properties is the file. Bill
Joined: Feb 27, 2002
Thank you for your reply, but how about when my class is not a servlet? in fact, i'm making a delegate to get data from ejb, then use a xml file to transform the data into something satisfy the client. If the class is not a servlet, which means I cannot use servletConfig, so what can I do to get the path from web layer name space? thank you again, and waiting for your reply.
Author and all-around good cowpoke
Joined: Mar 22, 2000
Take a look at the ServletContext API. You will find the methods such as getRealPath and getResourcePaths that you can use to get the real path to a file from the web-application relative path. Get the path in your init() method and keep it around as an instance variable to be passed to your helper class. Bill
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: how to use parameter defined in a web.xml?