【问题标题】:jsp:include not working with Expression Language (JSP version 2.5, EL enabled)jsp:include 不适用于表达式语言(JSP 版本 2.5,启用了 EL)
【发布时间】:2011-03-30 17:28:40
【问题描述】:

我读过: Expression Language in JSP not working 但略有不同。

使用 EL 引用文件可以正常工作,如下所示。

   <link rel="stylesheet" type="text/css" 
href="${pageContext.request.contextPath}/css/global.css"/>

但是,当尝试使用带有 EL 表达式的 JSP 包含标记时:

<jsp:include page="${pageContext.request.contextPath}/header.jsp" />

这会返回 http 500。

org.apache.jasper.JasperException: javax.servlet.ServletException: File &quot;/head_first/header.jsp&quot; not found
 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:527)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

我也确保启用 EL。

<%@ page isELIgnored ="false" %>

我的tomcat版本是6.0,web.xml定义JSP是2.5

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

有谁知道为什么 EL 只在 jsp:include 标记中使用时不起作用?

【问题讨论】:

    标签: jsp include expression


    【解决方案1】:

    EL 工作正常。上下文路径已打印。但是您不需要为上下文路径添加前缀 jsp:include page。它已经隐含地相对于上下文路径。即不可能包含来自其他上下文的文件。您的方法最终将包含在来自/head_first/head_first/include.jsp 的文件中,因此该文件不存在。

    【讨论】:

    • 感谢您的提示,我在这里有点困惑。我想如果我想包含一个 jsp 文件,可以使用 之类的东西。您能否更具体地说明我该如何解决此问题?
    • 哦,我想我明白了。
    • 是的,你不需要在它前面加上上下文路径。
    猜你喜欢
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 2012-01-05
    • 2011-08-16
    • 2010-12-19
    • 1970-01-01
    相关资源
    最近更新 更多