Spring MVC - Prevent Duplicate Form Submission MCQ
0/13
0✓
0✗
1. What can happen if a user refreshes the page right after a form was submitted with POST and the result page was returned directly?
Why: When the result page is the direct response of a POST request, a refresh repeats that POST. The same form can be submitted more than once.
2. Which technique is commonly used to avoid duplicate form submission?
Why: A redirect after a successful POST makes the browser load the result page with a new request. Refreshing the page then does not send the form again.
3. What is the name of the common pattern where the server redirects after processing a POST request?
Why: In the Post/Redirect/Get pattern, the form is sent with POST, the server answers with a redirect, and the browser then loads the result page with GET.
4. After the server sends a redirect response, which HTTP method does the browser ideally use to request the result page?
Why: The browser makes a new request to the redirect URL, ideally using GET. This is what makes a page refresh safe.
5. Why is it good that the result page is loaded with GET after a redirect?
Why: A refresh only repeats the GET request for the result page. The original POST request with the form data is not sent again.
6. What does the browser's address bar show after a successful form submission that ends with a redirect?
Why: Because the browser follows the redirect, the address bar is updated to the redirect target URL instead of the form URL.
7. How does a redirect work?
Why: A redirect is a response that asks the browser to send a new request to a different URL. A forward, in contrast, happens inside the server.
8. Which return value of a Spring MVC handler method triggers a redirect?
Why: The redirect: prefix in a returned view name tells Spring MVC to send a redirect response to the given URL.
9. Which HTTP status code is commonly used by Spring MVC when it sends a redirect response with the redirect: prefix?
Why: A redirect response normally uses status 302 (Found) together with a location header that holds the new URL.
10. A form is submitted and validation fails. What is the usual approach in the handler method?
Why: The redirect is done only after the form data is processed successfully. When validation fails, the form view is shown again with the error messages.
11. Why can data stored as a normal request attribute not be used by the page shown after a redirect?
Why: A redirect makes the browser send a brand new request. Request attributes of the old request are not available in the new one.
12. In Spring MVC, which feature lets you pass data to the page shown after a redirect without putting it in the URL?
Why: Flash attributes are saved temporarily and made available to the next request, which is the request made after the redirect.
13. How long are flash attributes available?
Why: Flash attributes are kept just long enough to be used by the request after the redirect. After that they are removed.
14. Which method of RedirectAttributes adds a flash attribute?
Why:addFlashAttribute() stores data that survives one redirect, so the page after the redirect can use it.