File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 60822
    
  65

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: 60822
    
  65

Not Tomcat-specific, so moved to the Servlets forum.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Possible to change status code sent by response.sendRedirect
 
Similar Threads
RequestDispatcher vs Response.sendRedirect
Unable to match database value with string
Page redirection problem.
server side redirect
How to Auto Minimize a JFrame