在JAVA里写链接

来源:百度知道 编辑:UC知道 时间:2024/06/16 20:28:37
RT:

window.location.href = "<%=request.getContextPath()%>"+"/web/index-1.jsp";

怎么在jsp的<% %>里写上跟上面这句相同功能的代码?

3Q~~~

<%="window.location.href =\""+request.getContextPath()+"/web/index-1.jsp\";"%>

request.getContextPath()应该是得到项目的名字,如果项目为根目录,则得到一个"",即空的字条串,
如果项目为abc, <%=request.getContextPath()% >/ 将得到abc/,服务器端的路径则会自动加上,
<a href="XXXX.jsp"> 应该就是指当前路径下的这个xxx.jsp页面,有时候也可以在head里设置html:base
来解决路径的问题,不过用的最多的还是request.getContextPath。