• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem while passing file name as parameter

 
sun moon
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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
 
Jesse Beaumont
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!