views:

521

answers:

3

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  A: 

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
A: 

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
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
+4  A: 

See http://stackoverflow.com/questions/472500/javascript-string-replace-str-works-weirdly-in-jsp-file/472573#472573 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.

Peter Štibraný
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