Spring and JSP EL not being processed

2019-07-25 08:51发布

问题:

We are running Tomcat 6.0 with Spring 3.0.5 an for some reason we can not get the jsps to evaluate the ${blah}. This is a maven project with many separate modules if that matters, Eclipse Helios.

Here is a snipped of my web.xml

<web-app id="WebApp_ID" version="2.5" 
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">
<display-name>xc.rio</display-name>...

And it isn't this (<%@ page isELIgnored="false" %>) because when I put this in my jsp the page is rendered as text only meaning

<%@ page isELIgnored="false" %>
<HTML>
...${blah}...

${2+2} is not evaluated. Also I have tried this on tomcat 7. =-(

Update: I have done a standalone spring and nonspring app and EL works. I was thinking it had something to do with the viewResolver, but that isn't it either I guess.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <mvc:annotation-driven />
    <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
        <property name="detectHandlersInAncestorContexts" value="true" /> 
    </bean> 

    <mvc:default-servlet-handler/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
      <property name="suffix" value=".jsp"/>
    </bean>

</beans>

回答1:

Try removing the <mvc:default-servlet-handler/> that causes spring to serve up pages as a static resources.