jsp中获取当前文件路径

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

posted on 2013-11-08 18:01  itmyhome  阅读(390)  评论(0编辑  收藏  举报

导航