因为android 在与服务器端交互时不会主动存储sessionId,所以需要手动进行存储
服务器端在第一次接收请求时(以struts2为例):
HttpSession s = ServletActionContext.getRequest().getSession();
String sessionId = s.getId();
s.setMaxInactiveInterval(-1);//session不过期
将sessionId返回即可
客户端:
HttpClient client = new DefaultHttpClient();
HttpPost httpRequest = new HttpPost(new URI(rootUrl + tailURL));
httpRequest.setHeader("Cookie", "JSESSIONID=" + 客户端存储的由服务器端返回的sessionId);
http://corejava5.iteye.com/blog/1213725