pageContext.request.contextPath 不起作用
我正在使用 Tomcat 6.0.32,并且尝试将 JSP 文件包含到另一个文件中,但不知何故找不到该文件(是的,该文件存在)。这是文件结构和代码:
<jsp:include page="${pageContext.request.contextPath}/templates/header.jsp">
</jsp:include>
WebContent
- folder/caller.jsp
- templates/header.jsp
但是,如果我在其中使用 ${pageContext.request.contextPath} 来检查它是否正确输出,它会起作用,有谁知道为什么会发生这种情况?
I'm using Tomcat 6.0.32 and I'm trying to include a JSP file into another, but somehow the file cannot be found (yes, the file exists). Here is the file structure and code:
<jsp:include page="${pageContext.request.contextPath}/templates/header.jsp">
</jsp:include>
WebContent
- folder/caller.jsp
- templates/header.jsp
However, if I use ${pageContext.request.contextPath} outside of that to check if it outputs correctly, it works, does anyone know why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我什至不确定是否可以在
中使用运行时变量,但另一个问题是contextPath
引用 所请求 URL 的上下文服务器,以及不一定对应于您的文件系统布局。为什么不直接使用
?I'm not even sure if you can use runtime variables inside a
<jsp:include>
, but the other problem is that thecontextPath
refers to the context of the URL being requested from the server, and does not necessarily correspond to your filesystem layout.Why wouldn't you just use
<jsp:include page="templates/header.jsp">
?我完全同意上面的答案,但是如果你必须这样使用它,那么下面的代码就可以工作
i completely agree with the above answer however if u have to use it this way then the below code shd work