Web development prevents the browser's refresh button from causing system operation repeated submission

xiaoxiao2021-03-05  20

The user interface of the web system is often displayed in the browser via HTML scripts, where the browser's refresh feature will resubmit the URL request for the current page. This will appear as follows: Return to a record list page after a new edited page store, when using the refresh button in this list page, the user's intent should be to refresh the current record list, but this time is submitted. It is a request to add a record storage, which may appear to submit an error to the server.

How to solve this problem, first recognize that the URL request after submitting the store operation, the URL request to directly submit the display list page is different for the different effects of the refresh operation displayed by the client, we can use the storage operation after operation The log list page shown by the client is the same as the page properties of the client and the page properties of the Direct Request List, allows the refresh operation to submit only the requested list display. We can use the Redirect feature provided by Java Servlet to separate the storage function and display record list. After completing the storage operation, return to the request to return the recording list to the client browser, so that the browser is displayed. The request attribute of the list page is the URL requesting the log list display, and the file is sent directly to the request for the log list page.

In the currently popular Struts framework, it is easy to revert to the

Type = "xxx.saveRecordAction"

Name = "Recordform">

After setting the recording store operation (/SAVERECORD.DO) After completing successfully, redirect to the Record List Display (/RecordList.do) Request, if the operation fails, redirect to the editing interface (/Recordedit.do) Continue to modify.

It should be noted that the redirected request does not automatically obtain the current request REQUEST data, and of course, various form submitted data, so the most annoying in actual use may be the various parameters required to redirect requests. In the redirected URL string.

For the above configuration example, assume that our /RecordList.do requests need a parameter is RECORD_ID = XXX, we can set a few parameters with the following code in XXX.sAveRecordAction:

Public ActionForward Execute (ActionMapping Mapping, Actionform Form, HttpservletRequest Request, httpservletResponse response) throws exception {... // 去 处理 处理 存盘 代 代

转载请注明原文地址:https://www.9cbs.com/read-38457.html

New Post(0)