关于Servlet开发中的目录

来源:互联网 发布:淘宝县级运营中心加盟 编辑:程序博客网 时间:2024/05/18 20:51

最近再用Servlet,但是被各种目录搞得七荤八素,然后用下面的代码理顺了:)


public static void show(HttpServlet servlet,HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{System.out.println("*************** REQUEST PATH");System.out.println("*************** request.getContextPath(): " + request.getContextPath());//System.out.println("*************** request.getRealPath(\"/\"): "+request.getRealPath("/"));//这个目前已经画删除线了System.out.println("*************** servlet.getServletContext().getRealPath(\"/\"): "+servlet.getServletContext().getRealPath("/"));System.out.println("*************** servlet.getServletContext().getRealPath(\"/WEB-INF\"): "+servlet.getServletContext().getRealPath("/WEB-INF"));System.out.println("*************** servlet.getServletContext().getRealPath(\"/WEB-INF/pic\"): "+servlet.getServletContext().getRealPath("/WEB-INF/pic"));System.out.println("*************** request.getPathInfo(): " + request.getPathInfo());System.out.println("*************** request.getServletPath(): " + request.getServletPath());System.out.println("*************** request.getRequestURI(): " + request.getRequestURI());System.out.println("*************** request.getRequestURL(): " + request.getRequestURL());System.out.println("*************** System.getProperty(\"java.io.tmpdir\"): "+System.getProperty("java.io.tmpdir"));System.out.println("*************** File.separator: "+File.separator);}

相信看完就全明白了。