JSP页面中获得上下文路径

 

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

在下面用<%=basePath%>就可以了

 

request.getScheme():获取请求协议

request.getServerName():获取域名

request.getServerPort():获取端口号

request.getContextPath():获取上下文(如果部署在根目录下,则该值为空)

你可能感兴趣的:(jsp)