wood burning stoves
The moose likes Servlets and the fly likes Possible to change status code sent by response.sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Possible to change status code sent by response.sendRedirect" Watch "Possible to change status code sent by response.sendRedirect" New topic
Author

Possible to change status code sent by response.sendRedirect

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Tomcat 6.0.26 (Java 1.6). By default, the "response.sendRedirect" method sends a 302 (Moved Temporarily) status code to the client. Is it possible to set the default behavior to have this command send a "301" (Moved Permanently) instead, or do I just need to avoid using response.sendRedirect altogether?

Thanks, - Dave
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62139
    
  68

No "by default" about it. That's what a redirect is. If you don't want a redirect, don't use sendRedirect(). You can set the response headers as you wish using the other methods.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62139
    
  68

Not Tomcat-specific, so moved to the Servlets forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Possible to change status code sent by response.sendRedirect