2012-07-10 36 views
2

我在重定向頁面時遇到問題。Spring MVC + Apache tiles,表單驗證和重定向

控制器:

@Controller 
@RequestMapping("/user") 
public class UserController { 

    @RequestMapping(method = RequestMethod.POST) 
    public String processSubmit(@Valid User user, 
      BindingResult result) { 

     if (result.hasErrors()) { 

        return "userForm"; 

        **It will show error - Could not resolve view with name 'userForm' in servlet with name 'dispatcher'** 


        return "redirect:user.htm"; 

        **It will redirect page but without error messages**              

     } else { 
      **same problem here** 
      return "userResult"; 
     } 
    } 

    @RequestMapping(method = RequestMethod.GET) 
    public ModelAndView initForm(ModelAndView model) { 
     User us = new User(); 
     model.addObject("user", us); 
     return model; 

    } 

} 

調度員的servlet:

<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
    <property name="viewClass"> 
     <value> 
      org.springframework.web.servlet.view.tiles2.TilesView 
     </value> 
    </property> 
</bean> 
<bean id="tilesConfigurer" 
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
    <property name="definitions"> 
     <list> 
      <value>/WEB-INF/tiles.xml</value> 
     </list> 
    </property> 
</bean> 

的web.xml:

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

沒有磚是一切就OK了。但是,當我配置調度程序使用瓷磚,重定向不工作,我不知道如何解決它。

+1

「userResult」是否爲瓦片的名稱? – 2012-07-10 22:01:33

+0

不,但非常感謝你的問題。我知道現在的問題在哪裏:)。 – enkor 2012-07-11 08:12:03

+0

然後請編輯/發佈解決方案並將問題標記爲已解決:) – 2012-07-11 13:55:13

回答

3

解決方案:

我必須返回tile的名稱而不是jsp文件。感謝jerome。