Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I get the redirect location from header?

843833Aug 24 2001 — edited Aug 25 2001
I am in a project which need a JSP script to get the header information from a URL (redirect) - the status code and the redirect location. I used following to simulate the situation.

script 1: test1.jsp
<%-- distination page --%>
<%
out.println("You have been redirected to this page");
%>

script 2: test2.jsp
<%-- this page redirect the client request to the test1.jsp when called. --%>
<%
String redirection = "http://127.0.0.1/test/test1.jsp";
response.setContentType("text/html; charset=ISO-8859-1");
response.setHeader("Location", redirection);
response.setStatus(303);
%>

script 3: test3.jsp
<%-- this page suppose to capture the status code that specified at test2.jsp --%>
<%@ page import="java.net.*" %>
<%
try {
URL url = new URL("http://127.0.0.1/test/test2.jsp");
out.println(url.toString());
HttpURLConnection hurlc = (HttpURLConnection) url.openConnection();
out.println("<br>" + hurlc.getResponseCode());
out.println("<br>" + hurlc.getResponseMessage());
int i = 0;
while(hurlc.getHeaderField(i) != null) {
out.println("<br>" + hurlc.getHeaderFieldKey(i) + ": " + hurlc.getHeaderField(i));
i++;
}
}
catch (Exception e) {
out.println("<br>" + e.toString());
}
%>


************************
the test3.jsp suppose to get the code 303 but it actually got code 200. following are the results:


http://127.0.0.1/test/test2.jsp
200
OK
null: HTTP/1.0 200 OK
Server: JRun Web Server
Date: Fri, 24 Aug 2001 17:14:53 GMT
Set-Cookie: jsessionid=55418998673293300;path=/
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Connection: Keep-alive
Cache-Control: no-cache="set-cookie,set-cookie2"
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 8

**SOME ONE COULD HELP ME? I need to get the redirect "Location" url in the response header as test2.jsp put in there.

Thanks a lot!

usg9620
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 22 2001
Added on Aug 24 2001
6 comments
1,848 views