aspose file tools*
The moose likes Servlets and the fly likes Help with directory tree in JSP/Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help with directory tree in JSP/Servlet" Watch "Help with directory tree in JSP/Servlet" New topic
Author

Help with directory tree in JSP/Servlet

Sam Zheng
Ranch Hand

Joined: Nov 29, 2000
Posts: 61
I am creating a simple JSP to access a servlet.
Within the servlet, I try to access a local file.
Now I have trouble to access this local file, I presume
that I mess up the search path for the file. Here
is my directory tree:
webdev/myJsp.jsp (the jsp file within which a servlet will
be called)
webdev/Web-Inf/myServlet.class (the servlet file to be called
by myJsp.jsp)
webdev/Web-Inf/myFile.txt (local txt file to be accessed by
myServlet.class)
Question #1:
In order to call myServlet from myJsp, how to construct
a relative path?
Question #2:
I have put the local file myFile.txt in the same directory
as the servlet myServlet, when I try to access this file
through FileReader:
FileReader fr=new FileReader("myFile.txt");
An exception is thrown during run time saying that it cannot
file this file. WHERE SHOULD I PUT MY local file for
access by servlet?
By the way, I am using Tomcat. Thanks for your help!
Sam
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I think you have put the files in the wrong places.
Servlet classes should be in webdev/WEB-INF/classes
and files to serve should be in webdev
The you can redirect to the servlet from the JSP (or invoke the servlet on its own). To read a file from a servlet or JSP, you should always use "getPathTranslated", as the servlet container may place files in "interesting" places.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with directory tree in JSP/Servlet