
public class FormLoginDemo
{
static final String LOGON_SITE = "developer.java.sun.com"
static final intLOGON_PORT = 80
public FormLoginDemo() {
super()
}
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient()
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http")
PostMethod authpost = new PostMethod("/servlet/SessionServlet")
// 准备登录参数
NameValuePair action = new NameValuePair("action", "login")
NameValuePair url = new NameValuePair("url", "/index.html")
NameValuePair userid = new NameValuePair("UserId", "userid")
NameValuePair password = new NameValuePair("Password", "password")
authpost.setRequestBody(
new NameValuePair[] {action, url, userid, password})
// 执行Post请求
client.executeMethod(authpost)
// 打印状态码
System.out.println("Login form post: " + authpost.getStatusLine().toString())
// 释放连接
authpost.releaseConnection()
}
}
//前端要调用后端的接口可以是用jsonp前端写法:
$.ajax({
url:"/xxx.java",
data:{type:"xxx",a:"aaa"},
async: false,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "returnLiveViewData",
success: function (msg) {
},
error:function(){
alert(请求失败)
}
}
//后端返回结果
"returnLiveViewData({"records": [{"name": "aaa", "IP": "11.11.11.11", "node": 114, },{"name": "bob", "IP": "11.11.11.22", "node": 115, },]}
)"
这跟java没关系吧,做一个页面的form提交就可以了
<form action="***" method="post" target="_blank">这里写你要提交的参数
</form>
然后提交你这个form就可以了
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)