File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to redirect but return code 200 ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to redirect but return code 200 ?" Watch "How to redirect but return code 200 ?" New topic

How to redirect but return code 200 ?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401

Does anyone how I can redirect a request to another url, but still return code 200?

I have tried:


but it returns code 302.

(I know it's not technically correct to return code 200, but I need to bend the rules a bit here...)

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13035
Seems to me the status can only have one value - either 200 or 302.
Maybe you need to redesign.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
302 is mandated for a redirection, it tells the browser to ignore any content that's part of the response and instead request the other resource pointed to as the redirection URL.

Why would you want to change the status code anyway? The user never sees it...

To be sure to return a 200, use forwarding of the request instead of redirection of the response.
That way the client never knows that you're handing off the request to another resourse, everything is handled inside your own server.

I agree. Here's the link:
subject: How to redirect but return code 200 ?
jQuery in Action, 3rd edition