关于java:Spring mvc结果页面和返回浏览器按钮 | 珊瑚贝

Spring mvc result page and back browser button


在我的 MVC spring 应用程序中,我使用 post 方法将表单发送到页面以执行带有一些参数的搜索。搜索结果是一个列表,并且对于每个条目都可以导航到详细信息页面。它工作正常,但是,当用户尝试使用返回浏览器按钮(或 Javascript)返回结果页面时,我收到”过期页面”错误。刷新页面,它重新执行帖子提交并且工作正常。

为了防止这个错误,我添加了

1
response.setHeader(“Cache-Control”,“no-cache”);

到搜索控制器,Safari 和 Firefox 一切正常,但是当我尝试使用 IE(8 和 9)执行 Web 应用程序时,我得到相同的”过期页面”错误。

转到详细信息页面并返回而不会出现任何错误的正确方法是什么?

感谢您的宝贵时间!Andrea


正确的方法是使用GET而不是POST:搜索是幂等操作,不会对服务器造成任何改变,这样的操作应该使用GET来完成。


不使 POST 请求过期似乎破坏了 POST 的概念:

Per RFC 2616, the POST method should be used for any context in which a request is non-idempotent: that is, it causes a change in server state each time it is performed, such as submitting a comment to a blog post or voting in an online poll.

相反,我会重组您查看详细记录的方式,可能会使用不会刷新显示结果的基础页面的覆盖 DIV。对于许多现代 Web 应用程序,使用 BACK 按钮可能会导致页面流程出现问题。

  • 我理解你的观点,基本上我同意,但在这种情况下,我需要重构应用程序的很大一部分。每次我回到我的页面时,有没有办法重新提交价值? (即在会话中存储表单参数?使用@ModelAttribute 似乎不可能做到这一点
  • 如果是这种情况,您的页面后退按钮不应该只是返回历史记录中的 1;而是在您的处理程序方法中获取参数并将它们添加回 Model 以便您可以将它们发送回 JSP 以供重用。后退按钮可以是旧表单的提交。


来源:https://www.codenong.com/11120989/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9920.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?