jsp页面自动生成的basePath脚本,端口号后面为什么少一个”/”?

<%
String path = request.getContextPath;
String basePath = request.getScheme+"://"+request.getServerName+":"+request.getServerPort+path+"/";
%>

request.getServerPort后面为什么不加”/”? myeclipse自动生成的jsp界面都不加,网上的好像也都不加。

打印下path 就知道了

可以看下源码方法的说明文档。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.

发表评论

电子邮件地址不会被公开。 必填项已用*标注