【问题标题】:Another option to POST redirectPOST 重定向的另一种选择
【发布时间】:2013-09-17 05:34:42
【问题描述】:

我正在使用 Spring,其中 requestMapping 被定义为一个方法,该方法存储用户在名为“a.html”的表单上创建的所有条目,并且正在使用的方法是 POST。提交此 a.html 后返回到调用它的页面,从该页面调用 index.html,但 URL 仍然显示“a.html”,并且在执行刷新操作时,它尝试重新提交,这导致了我们无法接受的问题。

有没有办法发布并在表单提交时返回 index.html,URL 是“index.html”而不是“a.html”。注意我们不能使用重定向,因为 html 被发送到另一个不支持重定向的代理。除了在 POST 上重定向之外还有其他建议吗?

@RequestMapping("/a.html", "RequestMethod.POST")
public ModelAndView create()
{
 // code to fill up the form
 return new ModelAndView() //springframework.servlet

}

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    返回一个重定向:

     return new ModelAndView(new RedirectView("/index.html", true));
    

    最佳实践:始终在每个请求更改服务器上的内容时返回重定向

    【讨论】:

    • 但是我调用的服务代理不支持重定向。还有其他想法吗?
    猜你喜欢
    • 2016-05-03
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多