简体   繁体   English

Spring SimpleFormController-浏览器后退按钮不起作用

[英]Spring SimpleFormController - Browser back button not working

Controllers extending from SimpleFormController Http Method - Post 从SimpleFormController Http方法扩展的控制器-发布

After the form is submitted and I press on browser back button, the page expired appears and I have reload the page which resubmits the form. 提交表单后,我按浏览器的“后退”按钮,页面已过期,并且我已经重新加载了重新提交表单的页面。

However, I need that when user clicks on browser back button, he is not shown page expired page, but instead user is redirect to form page. 但是,我需要当用户单击浏览器后退按钮时,不会显示页面过期页面,而是将用户重定向到表单页面。

I currently thought of two approaches: 我目前想到了两种方法:

Change from POST to get & use below in controller: 从POST更改为在以下控制器中获取和使用:

@Override
protected boolean isFormSubmission(HttpServletRequest request) {
    return true;
}

Second way is to define cache time in constructor of controller: 第二种方法是在控制器的构造函数中定义缓存时间:

public VehicleDescController()
{
    setCacheSeconds(1);
}

The application is really old and uses XML based spring configurations. 该应用程序确实很旧,并且使用基于XML的spring配置。 I am also relatively new to Spring MVC. 我对Spring MVC还是比较陌生。

Please help me figure out the correct approach. 请帮助我找出正确的方法。 Thanks. 谢谢。

I normally like to have the Post method redirect to a Get method after it is done. 我通常喜欢在完成后将Post方法重定向到Get方法。 You keep the Post method in place, but you always redirect to a Get method to display a resulting page. 您将Post方法保留在适当的位置,但始终会重定向到Get方法以显示结果页面。 This will seem like a normal get operation to the user and you won't have the back browser issue. 对用户来说,这似乎是正常的get操作,并且不会出现后退浏览器问题。

If the Get method needs some data (example: a record id), then the Post can store that data in the user session and the Get method can look for that value in the user session. 如果Get方法需要一些数据(例如:记录ID),则Post可以将数据存储在用户会话中,而Get方法可以在用户会话中查找该值。 This is an easy way to "pass" data from the Post method to the Get method and it keeps that data in the user session if they do hit the back button to return to the page again. 这是一种将数据从Post方法“传递”到Get方法的简单方法,并且如果用户确实单击了“后退”按钮以再次返回到页面,则可以将数据保留在用户会话中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM