不用单点登录,模拟远程项目的登录页面表单,在访问这个页面的时候自动提交表单到此项目的登录action,就可以实现登录到其他系统。

ssh框架项目

1.以下是本地系统的action代码:

 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;
}
}

2.模拟的登录页面:

 <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>

最新文章

  1. [BCB] C++ Builder 绘图 绘制直线 —— 基于像素
  2. java 获取服务器 linux 服务器IP 信息
  3. C#图片处理---基础
  4. innerHtml and Jquery.html()
  5. dns (域名系统)
  6. 获取git的最后一次提交的commit id
  7. HDU 5521 [图论][最短路][建图灵感]
  8. hdu 5396 Expression(区间dp)
  9. CRM odata方法如何使用$top
  10. 利用LogParser将IIS日志插入到数据库
  11. (九)Delete an Index
  12. 基本排序算法Golang
  13. 1、html基础认识&amp;常用标签(1)
  14. Linux进程管理学习资料
  15. solr搜索分词优化
  16. 词向量编码 word2vec
  17. jQuery 获取对象 根据属性、内容匹配, 还有表单元素匹配
  18. Dockerfile编写的注意事项
  19. day85 ModuleForm Form组件
  20. Jenkins 基础入门

热门文章

  1. 简易的CRM系统案例SpringBoot + thymeleaf + MySQL + MyBatis版本
  2. EasyUI实现图片的上传后与其他文本框的提交以及DataGrid中图片的展示
  3. Java 5-11新特性的整理(转)
  4. 123457123456#0#-----com.twoapp.drawGame09--前拼后广--儿童画画游戏jiemei
  5. WIN 10 看不到SAMBA共享的硬盘
  6. html设置多个div并排显示
  7. iOS-UIScrollView+UIPageControl简单实现
  8. WordPress的Bootstrap面包屑导航
  9. Zabbix部分监控指标
  10. OpenGL学习笔记 之二 (色彩相关)