Spring MVC简单重定向控制器示例 [英] Spring MVC Simple Redirect Controller Example
问题描述
我正在尝试比较各种框架的重定向方法.
Hi I'm trying to compare the redirect methods of various frameworks.
我已经完成了很多:
- Cakephp
- CodeIgniter
- Django
- Grails
- Rails
- Zend Framework
但是,我一直试图为 JSF .
However I'm stuck trying to create the simplest example possible for Spring MVC and JSF.
我想要的是一个或两个处理/index和/redirect url的控制器,其中/index只是链接到/redirect,而/redirect使用301重定向来重定向回/index.
What I want is either one or two controllers which handle the /index and /redirect urls where /index simply links to /redirect, and /redirect uses a 301 redirect to redirect back to /index.
我找到了此文档,我只是没有足够的持久性来弄清楚如何在Spring MVC中创建这个看似简单的示例.
I found this documentation, I just don't have the persistence to figure out how to create this seemingly simple example in Spring MVC.
谢谢!
推荐答案
以防万一我在JSF和SPRING MVC中玩了重定向:
Just incase I played with redirect in JSF and SPring MVC:
JSF:
<navigation-rule>
<from-view-id>index.xhtml</from-view-id>
<navigation-case>
<from-action>#{actionController.actionSubmitted}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>index.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
Spring-MVC以POST/REdirect/GET设计模式提交用户表单:
Spring-MVC submitting user form in POST/REdirect/GET design pattern:
@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView index(){
ModelAndView mv = new ModelAndView("index");
User user = new User();
mv.addObject("user", user);
return mv;
}
@RequestMapping(value="/signin.html",method = RequestMethod.POST)
public ModelAndView submit(@Valid User user){
ModelAndView mv = new ModelAndView("redirect:index.html");
System.out.println(user.getFirstName());
return mv;
}
希望有帮助.
这篇关于Spring MVC简单重定向控制器示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!