--%>
//编码,解决中文乱码//String str = URLEncoder.encode(request.getParameter("name"),"utf-8");//设置 name 和 url cookie
HttpClient httpClient= newDefaultHttpClient();//RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD_STRICT).build();//CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
HttpPost httppost= new HttpPost("https://tdc.cloudiip.com/http/do.jhtml?router=systemIndexService.doLogin");
List params = new ArrayList();
params.add(new BasicNameValuePair("uuid", "7f0570ab4c704aeca037772b54b5f292"));
params.add(new BasicNameValuePair("account", "18612222442"));
params.add(new BasicNameValuePair("password", "abc123"));
params.add(new BasicNameValuePair("checkcode", "1234"));
params.add(new BasicNameValuePair("sub", "登录"));try{
httppost.setEntity(newUrlEncodedFormEntity(params));
httpClient.execute(httppost);//我们这里只是简单的打印出当前Cookie值以判断登录是否成功。
CookieStore cookieStore =((AbstractHttpClient) httpClient).getCookieStore();
List cookies =((AbstractHttpClient) httpClient).getCookieStore().getCookies();for(org.apache.http.cookie.Cookie cookiee : cookies){
javax.servlet.http.Cookie cookie= newjavax.servlet.http.Cookie(cookiee.getName(),cookiee.getValue());
cookie.setDomain(".cloudiip.com");
cookie.setPath("/");
cookie.setVersion(cookiee.getVersion());
cookie.setMaxAge(60*60*24);//设置cookie过期时间为24小时。//name.setMaxAge(60*60*24);//url.setMaxAge(60*60*24);//在响应头部添加cookie
response.addCookie(cookie);
System.out.println(cookie.getName()+"==="
+cookie.getValue()+"==="
+cookie.getDomain()+"======"+cookie.getVersion());
}
response.setStatus(200);
}catch(Exception e) {//TODO Auto-generated catch block
e.printStackTrace();
}finally{
httppost.releaseConnection();
}//从url中获取的重定向地址
String url = request.getParameter("url");%>
设置 Cookie