EL in a JSP stopped evaluating

一笑奈何 提交于 2020-01-04 06:32:09

问题


In a JSP page(index.jsp):

${requestContext.requestURL} is the URL

just shows the expression itself. It used to be evaluated to something like "http://.../somerset/"

I created the Maven project with maven-archetype-webapp archetype in Eclipse. The Jetty version is jetty-6.1.14.

My web.xml is simple:

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <servlet>
      <servlet-name>SomersetServlet</servlet-name>
      <display-name>SomersetServlet</display-name>
      <description></description>
      <servlet-class>com.foo.somerset.SomersetServlet</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>SomersetServlet</servlet-name>
      <url-pattern>/som.do</url-pattern>
    </servlet-mapping>
</web-app>

回答1:


See Javascript String.replace(/\$/,str) works weirdly in jsp file for some possible reasons.

Your web.xml should contain reference to web-app_2_4.xsd schema, like

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

This enables servlet 2.4 and jsp 2.0 processing, which includes EL.

Btw requestContext is not valid implicit object.




回答2:


Incorrectly matched quotes can cause this behavior, where the expression just gets treated as a string. Your IDE would normally highlight this in a different color if this is the case.




回答3:


Be sure you have directive, and other libraries you use included

<jsp:root .....

More info on definition here

http://java.sun.com/products/jsp/tags/12/syntaxref123.html



来源:https://stackoverflow.com/questions/504071/el-in-a-jsp-stopped-evaluating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!