• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to redirect but return code 200 ?

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic