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

查看:31
本文介绍了Spring MVC 控制器重定向使用 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 控制器重定向使用 URL 参数而不是响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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