Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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: 61095
    
  66

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: 61095
    
  66

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