Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to redirect but return code 200 ?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me the status can only have one value - either 200 or 302.
Maybe you need to redesign.
Bill
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic