2012-08-06 24 views
13

Spring 3.1.0で興味深い問題があります。 JSPページのELが評価されていません。私はビュー解決プロセスをデバッグし、JstlViewが使用されており、Jstlライブラリが検出されています。しかし、私のJSPページがちょうどSpring JSPページが評価されない

<%="Hello World!"%> 

のようなものをレンダリングする私のために働いてきたどれもこの問題について、ここでの言及はたくさんあります。上からSpring and JSP EL not being processed

Script tags not rendered in JSP page (using Spring + Tiles + JSPX) は、ここに私の設定です。

のweb.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app 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" 
    version="2.5">   

<servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath:applicationContext.xml</param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<listener> 
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
</listener> 
</web-app> 

ばねservlet.xml

<!--?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:p="http://www.springframework.org/schema/p" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
    <!-- 
    https://stackoverflow.com/questions/3652090/difference-between-applicationcontext-and-spring-servlet-xml-in-spring 
    -->   
</beans> 

applicationContext.xmlを

<!--?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:p="http://www.springframework.org/schema/p" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

<context:annotation-config /> 
<context:component-scan base-package="com.csc.fs.emea" /> 
<mvc:default-servlet-handler /> 
<mvc:annotation-driven /> 
<mvc:resources mapping="/static/**" location="/" /> 

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver" p:order="1" /> 
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:order="2" p:defaultErrorView="sorry" /> 

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> 
    <property name="templateLoaderPath" value="/WEB-INF/freemarker/" /> 
    <property name="freemarkerSettings"> 
     <props>    
      <prop key="default_encoding">UTF-8</prop> 
      <prop key="output_encoding">UTF-8</prop> 
      <prop key="auto_include">macros.ftl</prop> 
      <prop key="auto_import">spring.ftl as spring</prop> 
      <prop key="template_update_delay">${freemarker.template.update.delay}</prop> 
     </props> 
    </property> 
    <property name="freemarkerVariables"> 
     <props> 
      <prop key="googleAnalyticsId">${google.analytics.id}</prop> 
     </props> 
    </property> 
</bean> 

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
    <property name="viewResolvers"> 
     <list> 
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
       <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
       <property name="prefix" value="/WEB-INF/jsp/" /> 
       <property name="suffix" value=".jsp" /> 
       <property name="contentType" value="text/html;charset=UTF-8"></property> 
      </bean> 
      <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> 
       <property name="cache" value="true" /> 
       <property name="prefix" value="" /> 
       <property name="suffix" value=".html" /> 
       <property name="contentType" value="text/html;charset=UTF-8"></property> 
       <property name="exposeSpringMacroHelpers" value="true" /> 
      </bean>    
     </list> 
    </property>  
</bean> 

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="classpath:messages" /> 
</bean> 
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
    <property name="paramName" value="lang" /> 
</bean> 
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver"></bean>  
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
    <property name="interceptors"> 
     <ref bean="localeChangeInterceptor" /> 
    </property> 
</bean> 
</beans> 

私はContentNegotiatingViewResolverを使用しています。私はfreemarkerのものとRESTも持っています。

コントローラ

@RequestMapping("/") 
@Controller 
public class RootResource extends AbstractResource { 

    ...abridged... 

    @RequestMapping(value="/jsp", method = RequestMethod.GET, produces = "text/html") 
    public String getJSP(final Model m) {   
     return "example"; 
    } 
} 

example.jspは

<%@ page isScriptingEnabled="true" isELIgnored="false" %> 
<html> 
<head> 
    <title>Hello World JSP Page.</title> 
</head> 
<body> 
<font size="10"><%="Hello World!"%></font> 
</body> 
</html> 

私は、コントローラからビュー名として「例」を返して、あなたはそれが正しいに解決ログで見ることができますWEB-INF/jsp/example.jsp

22:35:13,049 DEBUG [[email protected]] [org.springframework.web.servlet.view.ContentNegotiatingViewResolver] Returning [org.springframework.web.servlet.view.JstlView: name 'example'; URL [/WEB-INF/jsp/example.jsp]] based on requested media type 'text/html' 
22:35:13,050 TRACE [[email protected]] [org.springframework.web.servlet.view.JstlView] Rendering view with name 'example' with model {} and static attributes {} 
22:35:13,054 DEBUG [[email protected]] [org.springframework.web.servlet.view.JstlView] Forwarding to resource [/WEB-INF/jsp/example.jsp] in InternalResourceView 'example' 

すべてが大丈夫ですが、JSPページが正しく評価されないことだけです。

example.jspは、私がWebアプリケーションを実行するために、Mavenの桟橋6プラグインを使用しています。この

<%@ page isScriptingEnabled="true" isELIgnored="false" %> <%="Hello World!"%> 

のように見えます。

私は何かシンプルなものが欠けていると確信しています。おそらく、「あまりにも長い間それを見ました」問題の1つです。

ありがとうございます。

アップデート1 - 私はちょうど/*から/spring/*に春のサーブレットマッピングを変更した今では動作します。だから私は逃した/*にマップされている春のサーブレットの周りのいくつかの詳細があります。

+2

<%= "Hello World!"%> 'はEL構文ではありません。 ELは '$ {" Hello World "}' –

+0

を読んでくれます。ありがとうございます。私はexample.jspを試していました。まだ喜びはありません。 – biddster

+0

申し訳ありませんが、私は明確にすべきでした、私はあなたの問題を解決するためにそれを期待していませんでした(申し訳ありません)それはちょうどコメントでした;-) –

答えて

32

「あまりにも長く見ました」の場合です。

スプリングサーブレットは、デフォルトのサーブレットである必要があります。すなわち、/にマッピングされ、/*にマッピングされません。

<servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>/</url-pattern>   
</servlet-mapping> 
+1

絶対にスポットが入った溶液。私はContentNegotiatingViewResolverをデバッグし、うまくいきました。確かに、なぜ私はワイルドカードのために生のJSPをレンダリングさせるのか理解できません。もう少し詳しく教えていただけますか?どうもありがとう。 –

+0

/このサーブレットをapp用のデフォルトサーブレットとして作成しますが、/ *はワイルドカードマッピングに過ぎません。 –

+0

ありがとう!私は怒っているつもりだった。 – asgs

関連する問題