2011-12-26 12 views
3

が動作していない私はポストURLに簡単なフォームを送信していると私はで送信していた値を見たいのですが春のMVCで3.1-リリースSpring MVCの3.1 RedirectAttributesは私がRedirectAttributesを実装しようとしている

を備えていますリダイレクト:

私のコントローラは、このようになります

@Controller 
public class DefaultController { 

    @RequestMapping(value="/index.html", method=RequestMethod.GET) 
    public ModelAndView indexView(){ 
     ModelAndView mv = new ModelAndView("index"); 
    return mv; 
    } 

    @RequestMapping(value="/greetings.action", method=RequestMethod.POST) 
    public ModelAndView startTask(@RequestParam("firstName") String firstName,RedirectAttributes redirectAttributes){ 
     redirectAttributes.addFlashAttribute("redirectAttributes.firstName", firstName); 
     ModelAndView mv = new ModelAndView(new RedirectView("success.html")); 
     return mv; 
    } 

    @RequestMapping(value="/success.html", method=RequestMethod.GET) 
    public ModelAndView successView(){ 
     ModelAndView mv = new ModelAndView("success"); 
     return mv; 
    } 
} 

は今私のサーブレットのXMLは次のようになります。

<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.1.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.1.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> 
<mvc:annotation-driven/> 
<context:component-scan base-package="com.vanilla.flashscope.controllers" /> 

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

私の問題は、success.htmlビューのredirectAttributesが空であることです。

<body> 
<h5>${redirectAttributes.firstName} </h5> 
</body> 

何も印刷しません。

+0

私は同じものを持っています。解決策が得られたら、教えてください。 – YNChumak

+0

はい、私はしました。私は私のコミュニティサイトでそれについてのいくつかの考えを書いて、それがあなたを助けることを願っています。 http://goo.gl/Qbym2 –

+0

Tks Danny。私は同じ問題を繰り返していた。キーはModelAndViewではなく文字列を返していましたが、奇妙に見えますが動作します。 –

答えて

2

「redirectAttributes」を削除する必要があるようです。キー名」

代わりのから:

 redirectAttributes.addFlashAttribute("redirectAttributes.firstName", firstName); 

これを行います。

redirectAttributes.addFlashAttribute("firstName", firstName); 
+0

こんにちは、この接頭辞の有無にかかわらず、キー名で完全に動作します。 –

関連する問題