1. 在jsp页面中取得网站的首页的路径
<%
String appContext = request.getContextPath();
Integer prot=request.getServerPort();
String basePath ="";
if(prot==80) //80为默认端口
basePath = request.getScheme()+"://"+request.getServerName()+ appContext;
else
basePath = request.getScheme()+"://"+request.getServerName()+":"+ request.getServerPort() + appContext;
%>
2. 在超链接中的写法
<a title="首 页" href="<%=basePath %>" target="_self">首 页</a>
<a title="美体" href="<%=basePath %>/fat" target="_self">美体</a>
3. 在浏览器html中显示的为:
<a title="首 页" href="http://www.txw100.com" target="_self">首 页</a>
<a title="美体" href="http://www.txw100.com/fat" target="_self">美体</a>