aspose file tools*
The moose likes Servlets and the fly likes how to use parameter defined in a web.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to use parameter defined in a web.xml?" Watch "how to use parameter defined in a web.xml?" New topic
Author

how to use parameter defined in a web.xml?

Sean Li
Ranch Hand

Joined: Feb 27, 2002
Posts: 154
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
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
Sean Li
Ranch Hand

Joined: Feb 27, 2002
Posts: 154
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use parameter defined in a web.xml?