<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
request.getServerPort()后面为什么不加"/"? myeclipse自动生成的jsp界面都不加,网上的好像也都不加。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
request.getServerPort()后面为什么不加"/"? myeclipse自动生成的jsp界面都不加,网上的好像也都不加。
可以看下源码方法的说明文档。request.getContextPath()获取的是项目的上下文路径,是一个相对路径。是"/"开头的
Returns the portion of the request URI that indicates the context
of the request. The context path always comes first in a request
URI. The path starts with a "/" character but does not end with a "/"
character. For servlets in the default (root) context, this method
returns "". The container does not decode this string.
4 回答1.6k 阅读✓ 已解决
4 回答1.4k 阅读✓ 已解决
1 回答2.7k 阅读✓ 已解决
4 回答2.2k 阅读
3 回答1k 阅读✓ 已解决
2 回答813 阅读✓ 已解决
2 回答1.4k 阅读
打印下path 就知道了