【问题标题】:why the "${}" tag in jsp output as a string为什么jsp中的“${}”标签输出为字符串
【发布时间】:2013-08-26 05:02:37
【问题描述】:

我想像这样在我的jsp中导入一个js文件

<script type="text/javascript" src="${pageContext.request.contextPath}/js/layout/jquery-ui.js"></script>

但是当我浏览已部署的页面时,我发现${pageContext.request.contextPath}part 在浏览器上显示为字符串,上面的代码尝试在${pageContext.request.contextPath}/js/layout/ 文件夹中查找js 文件而不是XXX/js/layout/

我的开发环境是“Myeclipse10.5+Tomcat7.0+JDK7.0”

【问题讨论】:

  • 页面是否包含其他未正确评估的 EL 表达式?
  • 此页面上的所有 EL 表达式均未正确评估..

标签: java jsp jakarta-ee


【解决方案1】:

检查您的 JSP 是否未配置为使用 page 指令忽略 EL

<%@ page ... isELIgnored="true" %>

或者,检查您的 web.xml 是否没有为所有 JSP 关闭 EL

<jsp-config>
  ...
  <el-ignored>true</el-ignored>
  ...
</jsp-config>


编辑

另外,请检查您的web.xml&lt;web-app&gt; 版本是否为2.4 或更高版本。将以下内容添加到您的 web.xml 作为解决方法(如果没有其他方法)

<jsp-config>
  <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <el-ignored>false</el-ignored>
  </jsp-property-group>
</jsp-config>

【讨论】:

  • no..实际上它运行良好,直到我上周更换我的计算机并重建我的工作区......
  • 只是路径错误127.0.0.1 - - [26/Aug/2013:12:35:01 +0800] "GET /$%7BpageContext.request.contextPath%7D/js/jquery.top.method.js HTTP/1.1" 404 180
  • 我在页面上添加了isELIgnored="false" 并且它可以工作....但我仍然找不到禁用它的位置....
  • 检查您的web.xml&lt;web-app&gt; 版本。应该是2.4
  • 这是我的 web.xml 头 &lt;web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" &gt;
【解决方案2】:

这是 Java EL(表达式语言)的一部分

看看http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html 的工作原理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 2021-02-26
    • 2020-01-22
    • 1970-01-01
    相关资源
    最近更新 更多