在jsp中,用如下代码
<a href="/index.jsp">index</a>
则该链接是指向webapps下的index.jsp。
用
<a href="index.jsp">index</a>
则该链接是指向该项目目录下的index.jsp。
在struct2中,若用
<a href="index.jsp">index</a>,
则该链接是指向的是该页面地址下的index.jsp。
如,该页面的地址是http://localhost:8080/structs001/path,
该链接是指向的是http://localhost:8080/structs001/path/hello.jsp。
为避免出现这种问题,可用绝对路径
String path=request.getContextPath(); String basePath=request.getScheme()+"://"+request.getServerName()+":" +request.getServerPort()+path+"/";
<base href="<%=basePath%>">。
转载请注明原文地址: https://ju.6miu.com/read-675806.html