jsp中文件路径的几种形式

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

out.println("basePath:"+basePath);
out.println("
"); out.println("getContextPath:"+request.getContextPath()); out.println("
"); out.println("getServletPath:"+request.getServletPath()); out.println("
"); out.println("getRequestURI:"+request.getRequestURI()); out.println("
"); out.println("getRequestURL:"+request.getRequestURL()); out.println("
"); out.println("getRealPath:"+request.getRealPath("/")); out.println("
"); out.println("getServletContext().getRealPath:"+getServletContext().getRealPath("/")); %>

demo.jsp显示:

basePath:http://localhost:8080/demo/

getContextPath:/demo
getServletPath:/demo.jsp
getRequestURI:/demo/demo.jsp
getRequestURL:http://localhost:8080/demo/demo.jsp
getRealPath:D:\Tomcat 6.0\webapps\demo\
getServletContext().getRealPath:G:\Tomcat 7.0\webapps\demo\


你可能感兴趣的:(javaee)