How to avoid resubmit in jsp when refresh?

后端 未结 7 1659
误落风尘
误落风尘 2020-12-07 23:05

I am writing a program, but i encounter a problem: when I refresh the jsp page, system will automatically resubmit the whole page, and i don\'t know how to avoid it, can so

7条回答
  •  悲哀的现实
    2020-12-07 23:53

    We can use Post/Redirect/Get (PRG) pattern to solve the issue of multiple submission of same data.

    It works as follows:

    First time when a user submits a form to server by POST or GET method, then we update the state in application database.

    Then we send a redirect response to send reply to client.

    Then we load a view by using GET command. There is no data is sent in this. Since this a new JSP page, it is safe from multiple submits. The code that processes the request is idempotent. So it does not do same action twice for same request.

提交回复
热议问题