import java.io.IOException;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
public class myLoginAction {
/**
* 查询是否用户已注册
* @return
* @throws Exception
*/
public void checkUser() throws Exception{
Loginer loginer = (Loginer) request.getSession()
.getAttribute("loginer");
String url = "http://www.youtest.com/login.php"; //远程系统登录action地址
String param = "username=Tom&password=123456"; //参数
String temp = "alert('用户名或密码错误');"; //返回的信息,此处是错误信息,用于比较。 视情况而定
boolean result =false ;
//验证数据是否能登录
result = sendPost(url, param, temp);
if(result){
return "login";
}else{
return "register";
}
}
//访问远程登录action并获取返回的信息
public static boolean sendPost(String url, String param, String temp) {
PrintWriter out = null;
BufferedReader in = null;
boolean result = true;
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
String line;
while ((line = in.readLine()) != null) {
if(temp.equals((line.trim()))) {
System.out.println("错误的line:"+line);
result = false;
}
}
} catch (Exception e) {
result = false;
logger.error("发送 POST 请求出现异常!"+e);
System.out.println("发送 POST 请求出现异常!"+e);
e.printStackTrace();
}finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}catch(IOException ex){
logger.error(ex);
ex.printStackTrace();
}
}
return result;
}
}
<html>
<head></head>
<body>
<script type="text/javascript">
var iframe = document.createElement("iframe");
iframe.src = "http://www.youtest.com/login.php?UNAME=<%=userName%>&UPWD=<%=pwd%>";
iframe.style.display="none";
var sta="false;"
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
window.location.href="http://www.youtest.com/index.html";
});
} else {
iframe.onload = function(){
window.location.href="http://www.youtest.com/index.html";
};
}
document.body.appendChild(iframe);
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有