我有一个JSP项目,在这个项目中,我试图在我的nav.jsp中创建一个指向我的frontpage (index.jsp)的链接,用于导航。
<nav>
<ul class="menu">
<li><a href="${pageContext.request.contextPath}/index.jsp"><span>Frontpage</span></a></li>
</ul>
</nav>但是当我运行我的项目时,导航到newWebsite2015.jsp。并尝试使用导航菜单中的链接返回。我得到以下错误。
HTTP Status 404 -/MyNewRandomBlog1.0/文章/index.jsp
但是为什么它要在index.jsp文件的文章文件夹中查找,而不是转到web目录的根目录并定位index.jsp呢?
在我的footer.jsp文件中,我使用pageContext.request.contextPath检索图像,这很好。
<img src="${pageContext.request.contextPath}/images/farOgSon-172x190px.png" alt="image1"/>所以我真的不明白它不适用于锚。
我的web.xml看起来就像
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>MyNewRandomBlog1.0</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

发布于 2015-03-04 21:19:26
${pageContext.request.contextPath}将采用您当前的上下文路径,以便它获取文章文件夹。
你应该用这个代替
request.getContextPath()/index.jsphttps://stackoverflow.com/questions/28864868
复制相似问题