Spring MVC Controller重定向使用URL参数而不是响应 [英] Spring MVC Controller redirect using URL parameters instead of in response

查看:348
本文介绍了Spring MVC Controller重定向使用URL参数而不是响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Spring MVC应用程序中实现RESTful url。一切都很好,除了处理表格提交。我需要重定向回原来的形式或成功页面。

I am trying to implement RESTful urls in my Spring MVC application. All is well except for handling form submissions. I need to redirect either back to the original form or to a "success" page.

@Controller
@RequestMapping("/form")
public class MyController {

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm() {
        // do my stuff
        return "myform";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processForm(ModelMap model) {            
        // process form data

        model.addAttribute("notification", "Successfully did it!");
        return "redirect:/form";
    }
}

但是当我在 Spring文档,如果重定向任何参数都会放到url中。这不适合我。

However as I read in the Spring documentation, if you redirect any parameters will be put into the url. And that doesn't work for me. What would be the most graceful way around this?

推荐答案

http://jira.springframework.org/browse/SPR-6464 为我提供了我需要的工作,直到Spring MVC提供的功能(潜在在3.0.2版本)。虽然我只是实现了他们暂时的类,并将过滤器添加到我的Web应用程序上下文。工作太棒了!

http://jira.springframework.org/browse/SPR-6464 provided me with what I needed to get things working until Spring MVC offers the functionality (potentially in the 3.0.2 release). Although I simply implemented the classes they have temporarily and added the filter to my web application context. Works great!

这篇关于Spring MVC Controller重定向使用URL参数而不是响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆