Show placeholder page when browser receives 302 request Show placeholder page when browser receives 302 request spring spring

Show placeholder page when browser receives 302 request


I believe your initial premise that when a browser receives a 302 response code it shows an error, might be incorrect.

You can see redirects happening in many websites where all the browser does is just change the address in the address bar and load the eventual page, without displaying anything in the mean time.

Moreover, the 302 HTTP status code is not intended to have a body part, and if it has one it is usually ignored. And so, I can think of only two things that may be happening:

  1. You're using some browser that has a different behavior when accepting a 302 code (older?).
  2. The server isn't sending a 302, and in fact is sending back a page with redirection code in it.

A good way to check this depends on which browser you're using, but most modern browsers have a 'developer' pane where you can see the outgoing requests and incoming responses and their headers and status codes. You can then verify what is actually happening.

If the case is the former, then I'm afraid there's probably not much you can do about it without altering the browser itself. If it is the latter, then assuming the server code is under your control, you can change whatever content is returned.


I assume this is what payment gateways are doing by displaying a page that says "Do not press back/refresh button"

To achieve this you can use meta tag to refresh / redirect. The following snippet is taken from this SO post

<meta http-equiv="refresh" content="3;url=http://www.google.com/" />


You can add a Custom error page

To map 302 to a static HTML file, you need to create an html file called 302.html under resources/public/error, your folder structure should look like:

src/ +- main/     +- java/     |        +- resources/         +- public/             +- error/                 +- 302.html