JSP页面中的重定向<<路径>>问题
1.JSP页面的一段代码
<body>
首页面<br/>
<a href=”hello.jsp”>hello.jsp</a>
</body>
问题:如果直接连接hello.jsp,tomcat找不到hello.jsp。
2.解决办法
(1)写成绝对路径
在jsp页面中都有下面的代码可以获取web应用的路径。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
那么连接可以用EL表达式写成
<a href=”<%=basePath %>hello.jsp”>hello.jsp</a>绝对路径
(2)jsp页面内定义base的全局路径
在jsp中添加如下代码
<base href=”<%=basePath%>”>
http://blog.sina.com.cn/s/articlelist_2540587351_0_1.html