복붙노트

[SPRING] 봄 JSP 페이지가 평가되지 않음

SPRING

봄 JSP 페이지가 평가되지 않음

Spring 3.1.0에서 흥미로운 문제가있다. JSP 페이지의 EL 평가가 없습니다. 뷰 해결 과정을 디버깅했으며 JstlView가 사용되고 Jstl 라이브러리가 감지되었습니다. 그러나, 나의 JSP 페이지는

<%="Hello World!"%>

여기에이 문제에 대한 많은 참고 자료가 있으며, 그 중 어느 것도 저에게 효과적이지 않았습니다.

JSP 페이지에서 렌더링되지 않은 스크립트 태그 (Spring + Tiles + JSPX 사용) Spring과 JSP EL이 처리되지 않음

상단에서, 여기 내 설정이야;

을 포함한다.

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

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

일부 freemarker 물건 및 거기에 너무 REST로 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"을 반환하고 올바른 WEB-INF / jsp / example.jsp로 로그하는 로그에서 확인할 수 있습니다.

22:35:13,049 DEBUG [1168657208@qtp-1342126426-0] [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 [1168657208@qtp-1342126426-0] [org.springframework.web.servlet.view.JstlView] Rendering view with name 'example' with model {} and static attributes {}
22:35:13,054 DEBUG [1168657208@qtp-1342126426-0] [org.springframework.web.servlet.view.JstlView] Forwarding to resource [/WEB-INF/jsp/example.jsp] in InternalResourceView 'example'

따라서 모든 것이 정상적으로 보입니다. JSP 페이지가 정확하게 평가되지 않습니다.

example.jsp는 다음과 같이 보입니다.

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

webapp을 실행하기 위해 Maven jetty 6 플러그인을 사용하고 있습니다.

나는 무언가 간단한 것을 놓치고있을 것이라고 확신한다. 아마도 "너무 오랫동안 그것을 보았다"문제 중 하나 일 것이다.

당신이 줄 수있는 포인터를 가져 주셔서 감사합니다.

업데이트 1 - 방금 스프링 서블릿 매핑을 / *에서 / spring / *로 변경했습니다. 이제는 작동합니다. 그래서 스프링 서블릿 주위에 / *에 맵핑 된 세부 사항이 있습니다.

해결법

  1. ==============================

    1.절대적으로 "너무 오랫동안 보았다"는 경우입니다.

    절대적으로 "너무 오랫동안 보았다"는 경우입니다.

    스프링 서블릿은 기본 서블릿이어야합니다. 즉 /와 /에 매핑되지 않습니다.

    <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>
    
  2. from https://stackoverflow.com/questions/11836641/spring-jsp-page-not-evaluated by cc-by-sa and MIT license