<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.io.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ex</title></head><body>
<%
String str1=request.getRequestURI();
String str2=application.getRealPath(request.getRequestURI());
String str3=application.getRealPath("/");
String str4=new File(application.getRealPath(request.getRequestURI())).getParent();
out.print(str1+"<br>");
out.print(str2+"<br>");
out.print(str3+"<br>");
out.print(str4+"<br>");
%></body>
</html>
得到的答案
/test/t/showImage.jsp
D:/jsp/test/t/showImage.jsp
D:/jsp/
D:/jsp/test/t
其中test是我配置server.xml的虚拟路径
D:/jsp/是我文件的绝对路径