2012-08-06 17 views
13

मुझे वसंत 3.1.0 के साथ एक दिलचस्प समस्या है। जेएसपी पृष्ठों में उनके ईएल का मूल्यांकन नहीं किया जा रहा है। मैंने दृश्य रिज़ॉल्यूशन प्रक्रिया को डीबग किया है और जेएसटीवी व्यू का उपयोग किया जा रहा है और जेएसटीएल पुस्तकालयों का पता लगाया गया है। लेकिन, मेरा JSP पृष्ठों जैसेवसंत जेएसपी पृष्ठ का मूल्यांकन नहीं किया गया

<%="Hello World!"%> 

बातें प्रस्तुत करना इस समस्या को, जिनमें से कोई भी मेरे लिए काम किया है के बारे में यहाँ पर संदर्भ के बहुत सारे हैं।

Script tags not rendered in JSP page (using Spring + Tiles + JSPX) Spring and JSP EL not being processed

ऊपर से, यहाँ मेरी config है;

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 का उपयोग कर रहा हूं क्योंकि मेरे पास कुछ फ्रीमार्कर सामान और आरईएसटी भी है।

नियंत्रक

@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> 

मैं अपने नियंत्रक से "उदाहरण" वापस दृश्य नाम के रूप में और आप लॉग यह सही करने के लिए हल करता है में देख सकते हैं वेब-आईएनएफ/जेएसपी/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' 

तो सबकुछ ठीक दिखता है, बस यह है कि जेएसपी पेज का कभी भी मूल्यांकन नहीं किया जाता है।

example.jsp इस

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

जैसे मैं webapp चलाने के लिए Maven घाट 6 प्लगइन का उपयोग कर रहा लग रहा है।

मुझे यकीन है कि मुझे कुछ आसान याद आ रही है, शायद यह उनमें से एक है "इसे बहुत लंबे समय तक देखा" मुद्दों।

किसी भी पॉइंटर्स के लिए धन्यवाद जो आप दे सकते हैं।

अद्यतन 1 - मैं सिर्फ वसंत सर्वलेट मानचित्रण /* से /spring/* को बदल दिया है और अब यह काम करता है। तो स्प्रिंग सर्वलेट के आसपास /* पर मैप किए जाने के बारे में कुछ विवरण है जो मैंने याद किया है।

+2

स्टार्टर्स '<% =" हैलो वर्ल्ड! "%>' ईएल वाक्यविन्यास नहीं है। ईएल '$ {" हैलो वर्ल्ड "}' –

+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 डीबग किया और यह ठीक काम कर रहा था। बेशक, मैं अभी भी समझ नहीं पा रहा हूं कि क्यों यह जंगली कार्ड की वजह से कच्चे जेएसपी को प्रस्तुत करने का कारण बनता है। क्या आप कृपया थोड़ी और विस्तारित करेंगे? बहुत बहुत धन्यवाद। –

+0

/इस सर्वलेट को ऐप के लिए डिफ़ॉल्ट सर्वलेट के रूप में बनाएं, लेकिन/* सिर्फ एक वाइल्ड कार्ड मैपिंग है। –

+0

बहुत बहुत धन्यवाद! मैं पागल होने वाला था। – asgs

संबंधित मुद्दे