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

problem while passing file name as parameter

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i m using tomcat and running jsp pages through it. In jsp i m using <use:beans> tag and creating instance of a class. In this class i hard coded a file name let suppose it be "Order.xml".
The final output should be, reading from the file "Order.xml" and displaying the content of the file on the web page.
Everything is working fine,
i placed the jsp file in webapps/school/jsp/
class file in webapps/school/web-inf/classes/
Order.xml file webapps/school/xml/
when i try to execute the jsp page it is displying error message that file is not found.
For "Order.xml" it is taking from root path as d:\tomcat4\bin.
can any one tell me why "Order.xml" is taking different path and what properties should i change to reslove it.
thanks in advance
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume this is because you are trying to get the file at path "Order.xml". This looks for the file in the present working directory, which is the present working directory of the tomcat server process (i.e. d:\tomcat\bin)
There are two solutions:
1. Use the full path to refer to the order.xml file
2. use the webroot relative path e.g. /WEB-INF/schools/xml/order.xml and user pageContext.getServletContext().getRealPath("/")
to translate that for you. (this assumes you are in a JSP or have pageContext available to you as an instance)
2 is a neater solution and is more portable because it doesn't assume anything about the underlying file system outside of the web application context.
Hope that helps
Jesse
 
reply
    Bookmark Topic Watch Topic
  • New Topic