aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to redirect but return code 200 ?" Watch "How to redirect but return code 200 ?" New topic
Author

How to redirect but return code 200 ?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hello,

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

I have tried:

response.setStatus(200);
response.sendRedirect(otherURL);
response.setStatus(200);

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...)

Cheers,
James
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
Seems to me the status can only have one value - either 200 or 302.
Maybe you need to redesign.
Bill
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.


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to redirect but return code 200 ?
 
Similar Threads
A simple servlet question
problem in HTTP response redirect
problem in HTTP response redirect
Issue in returning 302 response code instead of 200 response code
Forward to different URL and pass parameters