2011-02-08 2 views
2

Spring MVC를 지원하는 GWT 애플리케이션이 있습니다. 스프링 컨트롤러를 정의했습니다. import javax.servlet.http.HttpServletRequest;스프링 MVC 및 JSP - 컨트롤러에서 jsp로 데이터를 전달할 수 없습니다.

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class IndexController { 

    @RequestMapping("/") 
    public ModelAndView index(HttpServletRequest request) { 
     ModelAndView result = new ModelAndView("index"); 
     result.addObject("message", "hello, world!"); 
     return result; 
    } 
} 

이 컨트롤러는 간단한 JSP 기반보기 반환

<%@page pageEncoding="UTF-8"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 

<html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <title>Они с нами</title> 

    <link href="<%=getServletContext().getContextPath()%>/style/reset.css" rel="stylesheet" type="text/css"></link> 
    <link href="<%=getServletContext().getContextPath()%>/style/index.css" rel="stylesheet" type="text/css"></link> 
    <link href="<%=getServletContext().getContextPath()%>/style/common.css" rel="stylesheet" type="text/css"></link> 

    <script type="text/javascript" language="javascript" src="<%=getServletContext().getContextPath()%>/stub/stub.nocache.js"></script> 
    </head> 
    <body> 

    <p style="display:none">${message}</p> 
    </body> 
</html> 

URL 매핑 및보기로 리디렉션하여 작동 확인을하지만,

<p style="display:none">${message}</p> 

하지 작동하지 않습니다 - 그것은 단지 인쇄 $ {message}

내 web.xml은 다음과 같습니다.

<web-app> 
    <!-- Reads request input using UTF-8 encoding --> 
    <filter> 
     <filter-name>characterEncodingFilter</filter-name> 
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
     <init-param> 
      <param-name>encoding</param-name> 
      <param-value>UTF-8</param-value> 
     </init-param> 
     <init-param> 
      <param-name>forceEncoding</param-name> 
      <param-value>true</param-value> 
     </init-param> 
    </filter> 

    <filter-mapping> 
     <filter-name>characterEncodingFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

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

    <welcome-file-list> 
     <welcome-file>index/</welcome-file> 
    </welcome-file-list> 
</web-app> 

내 springMvc-servlet.xml에 :

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 

    <!-- POM file generated with GWT webAppCreator --> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.onisnami</groupId> 
    <artifactId>onisnami-site</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>GWT Maven Archetype</name> 

    <properties> 
    <!-- Convenience property to set the GWT version --> 
    <gwtVersion>2.1.1</gwtVersion> 
    <!-- GWT needs at least java 1.5 --> 
    <maven.compiler.source>1.6</maven.compiler.source> 
    <maven.compiler.target>1.6</maven.compiler.target> 
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> 
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-servlet</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-user</artifactId> 
     <version>${gwtVersion}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.7</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.googlecode.gwt.inject</groupId> 
     <artifactId>gin</artifactId> 
     <version>1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>net.customware.gwt.dispatch</groupId> 
     <artifactId>gwt-dispatch</artifactId> 
     <version>1.1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.inject</groupId> 
     <artifactId>guice</artifactId> 
     <version>2.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.inject.extensions</groupId> 
     <artifactId>guice-servlet</artifactId> 
     <version>2.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.amazonaws</groupId> 
     <artifactId>aws-java-sdk</artifactId> 
     <version>1.1.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>taglibs</groupId> 
     <artifactId>standard</artifactId> 
     <version>1.1.2</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <!-- Generate compiled stuff in the folder used for developing mode --> 
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory> 

    <plugins> 

     <!-- GWT Maven Plugin --> 
     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>gwt-maven-plugin</artifactId> 
     <version>2.1.0-1</version> 
     <executions> 
      <execution> 
      <goals> 
       <goal>compile</goal> 
       <!-- <goal>test</goal> 
       <goal>i18n</goal> 
       <goal>generateAsync</goal> --> 
      </goals> 
      </execution> 
     </executions> 
     <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
      documentation at codehaus.org --> 
     <configuration> 
      <runTarget>stub.html</runTarget> 
      <hostedWebapp>${webappDirectory}</hostedWebapp> 
     </configuration> 
     </plugin> 

     <!-- Copy static web files before executing gwt:run --> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.1.1</version> 
     <executions> 
      <execution> 
      <phase>compile</phase> 
      <goals> 
       <goal>exploded</goal> 
      </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <webappDirectory>${webappDirectory}</webappDirectory> 
     </configuration> 
     </plugin> 

    </plugins> 
    </build> 

</project> 

A는 솔루션의 검색에서 하루 종일 보냈다, 그러나 그것은 여전히 ​​작동하지 않습니다 또한

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

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>/WEB-INF/jsp/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 

    <context:component-scan base-package="com.onisnami.site.server.controllers"/> 
</beans> 

은 pom.xml 파일 . 도와주세요, 제발.

가 다음 줄을 추가 할 필요가 : 이 솔루션은 발견 당신에게

+0

참조 http://stackoverflow.com/questions/2168832/expression-language-in-jsp-not-working – axtavt

+0

왜 <% = getServletContext(). getContextPath() %>/style/reset.css를 사용하고 있습니까? 대신에? – Matt

답변

0

감사합니다 JSP 파일의 시작에서

<%@page contentType="text/html;charset=UTF-8" language="java" %> 
<%@page isELIgnored="false" %> 

2

당신이 정의되어 있기 때문에 당신이 올바른지 표현식

${Anything between this is expression} 

<%@page isELIgnored="false" %> 

isELIgnored is false, 즉 표현식이 고려됩니다.

관련 문제