2

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>
yogman
  • 4,021
  • 4
  • 24
  • 27

3 Answers3

8

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.

Community
  • 1
  • 1
Peter Štibraný
  • 32,463
  • 16
  • 90
  • 116
  • It's working! Previously it worked, and as I moved to Maven, Maven archetype auto-generation forgot to add those attributes! Thanks! However, mvn jetty:run woked at first run, but in Eclipse, it requires several tries for EL to work. – yogman Feb 02 '09 at 18:18
1

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.

krosenvold
  • 75,535
  • 32
  • 152
  • 208
0

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

waney
  • 402
  • 1
  • 5
  • 20
  • As far as I know EL works without the declaration of any taglib, in fact, it doesn't use any taglib. And, <%= 10 * 20 %> correctly evaluates to 200. – yogman Feb 02 '09 at 18:01