HttpClient包是可以实现的
http://hi.baidu.com/zengjh/blog/item/4e2908d6ea665dd8a144df39.html
这有例子
http://hi.baidu.com/zengjh/blog/item/4e2908d6ea665dd8a144df39.html
这有例子
解决方案 »
- js给元素赋值(兼容性问题)
- 为Hidden赋值,弹出消息提示框的问题~问题解决满分送上!!
- _____________________一个小问题_______________________
- 求一正则表达式 要求既可以输入95.6 又可输入 60 (说简单点就是作分数格式的判断)
- 想问一下怎么在打开页面时自动弹出加入收藏的提示?
- 请问如何用js,保存页面刷新前的值
- iframe问题,急,解决里马给分
- multi_sort_table如何在js中实现多列排序??
- 列表在页面上怎么实现删除
- webpack +vue如何只编译src下的部分文件夹中的vue/js/css
- 如何实现这种功能??
- iframe设置高度
package DAO;
import org.apache.commons.httpclient.*;import org.apache.commons.httpclient.cookie.*;import org.apache.commons.httpclient.methods.*;
/*** 用来演示登录表单的示例* @author Liudong*/public class FormLogin{
static final String LOGON_SITE = "localhost"; static final int LOGON_PORT = 8080; public static void main(String[] args) throws Exception{ HttpClient client = new HttpClient(); client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT); //模拟登录页面login.jsp->main.jsp
String url1 = "http://xt.dhcc.com.cn";
String url2 = "http://xt.dhcc.com.cn/login3.do?version=jigang2006"; PostMethod post = new PostMethod(url1); NameValuePair name = new NameValuePair("userid", "yangguangwg"); NameValuePair pass = new NameValuePair("password", "mypassword"); post.setRequestBody(new NameValuePair[]{name,pass}); int status = client.executeMethod(post);
System.out.println(post.getStatusCode()); System.out.println(status);
System.out.println(post.getResponseBodyAsString()); post.releaseConnection(); //查看cookie信息
CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
Cookie[] cookies = cookiespec.match(LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies()); if (cookies.length == 0) { System.out.println("None"); } else { for (int i = 0; i < cookies.length; i++) { System.out.println(cookies[i].toString()); } } //访问所需的页面main2.jsp GetMethod get = new GetMethod(url2); client.executeMethod(get); System.out.println(get.getResponseBodyAsString()); get.releaseConnection(); }}输出结果是:
200
200
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0"><title>(正式库)东华协同办公管理平台 2007 北京东华合创数码科技股份有限公司 Copyright [email protected] (build 2008年九月28日 04时18分00秒 )</title>
<link href="scheme/style.css" rel="stylesheet" type="text/css">
<script language="javascript">
function String.prototype.Trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
function String.prototype.Ltrim(){return this.replace(/(^\s*)/g, "");}
function String.prototype.Rtrim(){return this.replace(/(\s*$)/g, "");}function login(){
var u = document.loginForm.userid.value;
var p = document.loginForm.password.value;
if(u.Trim()==""){
alert("请填写用户名");
document.forms[0].userid.focus();document.forms[0].userid.select()
return false;
}
if(p.Trim()==""){
alert("请填写密码");
document.forms[0].password.focus();document.forms[0].password.select()
return false;
}
return true;
}
</script><script language="javascript">
var strVersion=clientInformation.appVersion;
var strMsie="MSIE";
if (window.clientInformation.userAgent.indexOf( "MSIE " ) > 0)
{
// The browser is Microsoft Internet Explorer.
var nFindMsie=strVersion.search(strMsie);
nFindMsie=strVersion.substring(nFindMsie+6,nFindMsie+4); if(nFindMsie < 6)
{
alert("浏览器版本太低,要求至少IE6.0及以上版本");
window.open("help/help.jsp?helpid=env","_top")
}
}
else
alert("系统不支持该浏览版本,请使用 Microsoft Internet Explorer6.0及以上版本");
</script>
</head><body onLoad="document.forms[0].userid.focus();document.forms[0].userid.select()" background="scheme/images/loginbj01.gif" topmargin="108">
<span id="d3" style="position=absolute;visibility=visible; z-index=10;left:10px;top:10px">
<div STYLE="font-size:14pt;color:red">
<p></p>
</div></span>
<table width="602" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="scheme/images/login01.gif" width="602" height="82"></td>
</tr>
<tr>
<td><img src="scheme/images/login02.gif" width="602" height="56"></td>
</tr>
<form name="loginForm" action="login3.do?version=jigang2006" method="post" target="_self">
<tr>
<td height="166" align="center" valign="top" background="scheme/images/login03.gif"><table width="260" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="right"> </td>
</tr>
<tr>
<td width="27%" height="40" align="right" nowrap>用户名:</td>
<td width="73%"><input name="userid" id="userid" nextelemid="password" type="text" class="inputlogin"></td>
</tr>
<tr>
<td height="40" align="right" nowrap>密 码:</td>
<td><input name="password" id="password" nextelemid="recogcode" onKeyPress="if(event.keyCode==13) return login()" type="password" class="inputlogin"></td>
</tr>
<tr>
<td height="40" align="right" nowrap>识别码:</td>
<td><input name="recogcode" id="recogcode" nextelemid="submitbut" onKeyPress="if(event.keyCode==13) return login()" type="password" class="inputlogin"></td>
</tr>
<tr>
<td colspan=2 align=center><input id=submitbut type="submit" class="button" value=" 登 录 " > <input id=button33 type="button" class="button" value="取回密码" onClick="window.open('rpassword.html','_new','scroll=no,scrollbars=yes,status=no,help=no,resizable=no,left='+(screen.availWidth/2-600)+',top='+(screen.availHeight/2-110)+',width=300,height=220')"></td>
</tr>
</table></td> </tr>
</form>
<tr>
<td><img src="scheme/images/login05.gif" width="602" height="74"></td>
</tr>
</table>
<br>
<div align=center class=logintext><table width="602" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td align='left'>1、需要用IE6.0或6.0以上的浏览器,不支持腾讯TT和Firefox;<br>2、如有问题,请联系史海兵,联系方式:62662382;<br>3、平台永久域名 http://xt.dhcc.com.cn/。</td></tr></table></div>
<script type="text/javascript" src="http://js.tongji.cn.yahoo.com/632588/ystat.js"></script><noscript><a href="http://tongji.cn.yahoo.com"><img src="http://img.tongji.cn.yahoo.com/632588/ystat.gif"></a></noscript>
</body>
</html>None<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Pragma" content="no-cache">
<title>东华业务平台</title>
<link href="scheme/style.css" rel="stylesheet" type="text/css">
<script language="javascript"> function tipclick(){ window.close(); }</script>
</head><body bgcolor="#F8F8F8" leftmargin="20" topmargin="50">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" >
<tr>
<td height="100" align="center" nowrap class="TDstyle03"> <p><br>没有此用户或密码不正确! <a href="./"> 重新登录点击这里 </a><br>
<br>
<br>
<input type="button" onclick="tipclick();" name="tip" value="关 闭" class="button">
<br>
</p></td>
</tr>
</table>
</body>
</html>
高手指教下,在线等~~
我去模拟登陆Facebook的时候 发现提示需要客户端支持Cookie