我在用httpclient时最后定向到一个页面为什么会出现返回登录页面的情况呢?
以下是源代码,帮我查查看啊!public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod method = new PostMethod("/StarMap/loginservlet?tag=login");
// 传递username和userpassword模拟post方法传参给servlet
NameValuePair name = new NameValuePair("username", USERNAME);
NameValuePair pass = new NameValuePair("userpassword", USERPASSWORD);
NameValuePair[] namevaluepair = { name, pass };
method.addParameters(namevaluepair);
//
int status = client.executeMethod(method);
String location = null;
if (status == HttpStatus.SC_MOVED_PERMANENTLY
|| status == HttpStatus.SC_MOVED_TEMPORARILY) { System.out.print("response code :    " + status);
Header locationHeader = method.getResponseHeader("location");

if (locationHeader != null) {
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
} else {
System.err.println("Location field value is null.");
}
Header[] headers = method.getResponseHeaders();
for (int i = 0; i < headers.length; i++) {
if (headers[i] != null) {
response.addHeader(headers[i].getName(), headers[i]
.getValue());
}
}
Cookie[] logoncookies = client.getState().getCookies();
for (int i = 0; i < logoncookies.length; i++) {
Cookie tem_cookie = logoncookies[i];
javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie(
tem_cookie.getName(), tem_cookie.getValue());
cookie.setDomain(tem_cookie.getDomain());
cookie.setComment(tem_cookie.getComment());
cookie.setPath(tem_cookie.getPath());
cookie.setSecure(tem_cookie.getSecure());
cookie.setMaxAge(5 * 24 * 60 * 60);
response.addCookie(cookie);

} }

response.sendRedirect(location); }服务器是把站点的信息存在session中的