Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes response code for sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "response code for sendRedirect" Watch "response code for sendRedirect" New topic
Author

response code for sendRedirect

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I like to know the response code for sendRedirect

I developed a sample application which redirects the request from a servlet to a jsp.

I used [mozdev.org] Live Http Headers and traced the response header for redirects. What I found was


HTTP/1.x 302 Moved Temporarily


But Head First book claims the response code redirects is "301"

I want to confirm this


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

301 is "Moved Permanently"
302 is "Moved Temporarily"

For more information:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html


With LiveHTTPHeaders, you're seeing exactly what the server is returning.
[ December 15, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Thanks Ben

Under what circumstances will the Container issue a 301 response (or) what should I do to send a 301 response header.
[ December 16, 2005: Message edited by: Vishnu Prakash ]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
If you want to send a 301, just use response.setStatus(response.SC_MOVED_PERMANENTLY)


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

To add to Bosun's answer, you can see all of the response constants in the HttpServletResponse API:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletResponse.html
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Thanks for response Bosun and Ben.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: response code for sendRedirect
 
Similar Threads
response.sendRedirect is not working
Getting the response code from a redirect
Strange behaviour of Tomcat
how to send error messages from sendRedirect to Jsp from a servlet
http redirected downloads