在小脚本内写下如下代码

<%

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.println(path);
out.println(request.getScheme());
out.println(request.getServerName());
out.println(request.getServerPort());

%>

<base href="<%=basePath%>">

<%
out.println(basePath);
%>

打印结果如下

/divisionScope http localhost 8080 http://localhost:8080/divisionScope/

得到如下结论:

request.getContextPath()---项目名

request.getScheme()--------协议名

request.getServerName()---服务器名

request.getServerPort()-----端口名

bathPath----------------------相当于转发

posted on 2015-08-12 21:04  菜鸟乙  阅读(138)  评论(0编辑  收藏  举报