前提是在htm静态页面中实现
假设cookie中有两个变量name="123",site="http://www.000000.com",这两个变量可以改变的我要实现的效果就是把name和site在table或div显示出来,并且作为超链接显示,其中name是超链接的名称,site就是超链接的网址

解决方案 »

  1.   

    String LOGON_SITE = "www.000000.com";
    int LOGON_PORT = 80;
    HttpClient client = new HttpClient();
    client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
    // 模拟登录页面login.jsp->main.jsp
    PostMethod post = new PostMethod("/login.do");
    NameValuePair name = new NameValuePair("email",mail);
    NameValuePair pass = new NameValuePair("password",password);
    post.setRequestBody(new NameValuePair[] { name, pass });
    int status = client.executeMethod(post);
    System.out.println(status+post.getResponseBodyAsString());
    post.releaseConnection();
    CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
    Cookie[] cookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false,
    client.getState().getCookies());
    if (cookies.length == 0) {
    return null;
    } else {
    for (int i = 0; i < cookies.length; i++) {
    String c = cookies[i].toString();
    String[] cs = c.split("=");
    if(cs[0].equals("这个地方去取不同的value")){
    return (cs[1]);
    }
    }
    }
    return null;
    }