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
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.