• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to use parameter defined in a web.xml?

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
What's a year in metric? Do you know this metric stuff tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic