Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:01:52+00:00 2026-06-15T05:01:52+00:00

When a form is submitted, and then the user clicks the back button, how

  • 0

When a form is submitted, and then the user clicks the back button, how do I prevent the data from being resubmitted. A lot of what I have read indicates that the solution to this is to implement the PRG ‘pattern’.

I found this web page PRG Pattern that I’d like to use as an example.

When I execute this code, I can still click the back button and then re-click the submit button and have the form resubmit the data, even though it redirects. So, I’m not seeing how this is supposed to prevent resubmitting the form data.

So, using this page as an example, how could the code be modified to prevent this behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:01:53+00:00Added an answer on June 15, 2026 at 5:01 am

    PRG is used to prevent reload resubmit event, you can always go back to page from browser and submit the form with this

    to prevent this you can issue tokens while rendering form and while submitting send it to server and see if that is the right token (by putting it somewhere in session) then process the request

    update: when you serve the form set some token in session

    request.getSession().setAttribute("formToken", someCode);
    

    now on submit of form, post the token back to server, and match it with the one from session, if both matches allow the request, if doesn’t matches that means the request is already executed or some one is trying to simulate form post and missing the form token in submitted data,

    so now if you already have submitted once and if you go back using browser button and resubmit it again the code won’t match and it will prevent resubmission

    make the token check thing synchronized to handle parallel request case

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textarea I have submitted via a form. Then I get the
I have a basic POST form being submitted. Every time a form is submitted,
I have a form, on which I have a button - When the user
There is a form ,which is submitted and then the page is redirected to
I need to validate submitted form data: To check whether fields are empty. Proceed
I have an issue with the submitted form information. Decimal parsing fails when I
I have a form with an array of text fields. The user (through javascript)
I have several forms(user can add new form dynamically) in one page, they're all
I have a form with two buttons, a submit button and a cancel/close button.
I have a form with a single select_field that gets submitted via jquery whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.