我想在登录网站后使用会话缓存来触发一些操作。 下面我在groovy中编写了代码。 我坚持将会话缓存传递给我的行动。
{
HttpResponse httpResponse=null;
String responseString = null;
String appUrl = "test.com";
String actionName = "testUsers.action";
try {
httpPost = new HttpPost(appUrl + "/" + actionName);
//System.out.println("postmethod\t" + httpPost.getURI());
nameValuePair.add(new BasicNameValuePair("j_password", "test"));
nameValuePair.add(new BasicNameValuePair("j_username","test@test.com"));
nameValuePair.add(new BasicNameValuePair("login", "Login"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
httpResponse = httpClient.execute(httpPost);
//String server = httpResponse.getFirstHeader("Set-Cookie").getValue();
//System.out.println("httpResponse="+httpResponse);
//httpResponse.addCookie(server);
responseString = IOUtils.toString(httpResponse.getEntity().getContent());
} finally {
httpPost.abort();
}
}