80,490
社区成员
发帖
与我相关
我的任务
分享/**
* post方式提交表单(模拟用户登录请求)
*/
public void postForm() {
// 创建默认的httpClient实例.
CloseableHttpClient httpclient = HttpClients.createDefault();
// 创建httppost
HttpPost httppost = new HttpPost("http://localhost:8080/myDemo/Ajax/serivceJ.action");
// 创建参数队列
List<namevaluepair> formparams = new ArrayList<namevaluepair>();
formparams.add(new BasicNameValuePair("username", "admin"));
formparams.add(new BasicNameValuePair("password", "123456"));
UrlEncodedFormEntity uefEntity;
try {
uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
httppost.setEntity(uefEntity);
System.out.println("executing request " + httppost.getURI());
CloseableHttpResponse response = httpclient.execute(httppost);
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("--------------------------------------");
System.out.println("Response content: " + EntityUtils.toString(entity, "UTF-8"));
System.out.println("--------------------------------------");
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这个帖子应该发到web版块去啊...
不懂web。。。
不过按一般排查思路, 首先确定一下login方法到底有没有被调用, 如果没有被调用,是不是配置有问题?
关于url与action的映射,搜索到这篇文章http://my.oschina.net/zhengjian/blog/98291
祝你好运啊
Map<String,String[]> paramMap = request.getParameterMap();
for(Map.Entry<String,String[]> entry:paramMap.entrySet()){
String key = entry.getKey();
String[] value = entry.getValue();
System.out.println(key + " : " + value[0]);
}
这样看有没有输出?