<%
String path1 = application.getRealPath(request.getRequestURI()); //当前请求的JSP文件的物理路径
String path2 = application.getRealPath("/"); //当前WEB应用的物理路径
String path3 = request.getRequestURI();
StringBuffer path4 = request.getRequestURL(); //getRequestURL()返回的是StringBuffer
String virtualPath = request.getServletPath(); //虚拟路径
String realPath = request.getRealPath(virtualPath);//物理路径
%>
PS: request.getRequestURI()与request.getRequestURL()的区别
request.getRequestURI()只是显示的是文件的名称 // /cta/xiahu/xiahu_add.jsp
request.getRequestURL()显示的全部的URL // http://localhost:7001/cta/xiahu/xiahu_add.jsp
request.getRequestURL()显示的全部的URL // http://localhost:7001/cta/xiahu/xiahu_add.jsp
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19190.html