不用单点登录,模拟远程项目的登录页面表单,在访问这个页面的时候自动提交表单到此项目的登录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>

java 传入用户名和密码并自动提交表单实现登录到其他系统的更多相关文章

  1. ssi-uploader上传图片插件,点击选择文件按钮自动提交表单解决办法

    先介绍一下这款插件,然后再谈使用中可能遇到的问题 ssi-uploader是一个JQuery的图片上传插件,界面比较美观 github地址:https://github.com/ssbeefeater ...

  2. form表单下的button按钮会自动提交表单的问题

    form表单下的button按钮会自动提交表单的问题 2017年01月05日 18:02:44 蓝色水 阅读数:18012更多 个人分类: asp.net   form表单下的按钮在没有指定type类 ...

  3. 按钮特效-Enter键自动提交表单

    —————————————————————— <script type="text/javascript">                        //当用户按 ...

  4. 去掉chrome记住密码后自动填充表单的黄色背景

    chrome表单自动填充后,input文本框的背景会变成黄色的,通过审查元素可以看到这是由于chrome会默认给自动填充的input表单加上input:-webkit-autofill私有属性,然后对 ...

  5. alert警告框点击确定后自动提交表单

    转载于  :https://zhidao.baidu.com/question/619375120140398412.html 在页面中有多个input type="text"的文 ...

  6. 前端表单中有按钮button自动提交表单

    问题描述 在设计表单时,表单内有一个按钮<button>,该按钮是用来获取其他数据或执行其他操作的.并不是让他提交表单. 解决方案 1) 设置 form 的 onsubmit='retur ...

  7. JS倒计时,自动提交表单!

    <form id="frm" action="http://www.baidu.com"> 考试还剩余<div id="time&q ...

  8. <button>会自动提交表单吗?

    点击button以后,表单先由ajax提交,然后无论后台返回什么结果,页面都会跳转到表单action属性指定的路劲,也就是login.html使用的是html.jquery.javascript,后台 ...

  9. Java后台防止客户端重复请求、提交表单

    前言 在Web / App项目中,有一些请求或操作会对数据产生影响(比如新增.删除.修改),针对这类请求一般都需要做一些保护,以防止用户有意或无意的重复发起这样的请求导致的数据错乱. 常见处理方案 1 ...

随机推荐

  1. SVG-变换

    transform变换 translate平移 <svg width="200" height="50"> <rect x="0&q ...

  2. osg fbx 绘制坐标轴、控制模型影藏与显示

    int main() { osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer; osg::ref_ptr< ...

  3. 123457123457#1#-----com.threeapp.circlerunner01----儿童旋转跑酷游戏

    com.threeapp.circlerunner01----儿童旋转跑酷游戏

  4. 使用弹窗批量修改数据POPUP_GET_VALUES

    转自:https://blog.csdn.net/huanglin6/article/details/81231215 业务场景:在SAP内,有时候需要用户批量维护某些数据,这时候可以使用标准函数PO ...

  5. sqlserver如何创建链接服务器

    遇到下列问题: 线上服务器A,中转服务器B,本地服务器C 数据在A上面,想在B上面操作类似 select * from [A].[database].table这样的SQL,不用去链接服务器,直接把处 ...

  6. charles 开始/暂停记录

    本文参考:charles 开始/暂停记录 1.1. stop/start recording 和 2.1 recording settings 是常用的功能了:这里需要注意就是后面的session1代 ...

  7. centos(6,7) 系统常用命令

    目录: 系统服务命令 文件操作 系统信息 文件和目录 文件搜索 挂载一个文件系统 磁盘空间 用户和群组 文件的权限 压缩与解压缩 YUM丶RPM 包 查看文件内容 文本处理 文件系统分析 初始化一个文 ...

  8. GitLab基本使用

    一.引言 在微服务架构中,由于我们对系统的划分粒度足够小,服务会很多,而且也存在经常迭代的情况.如果还按照以前的部署方式显得非常吃力和复杂,并且很容易出现错误.而随着容器技术的发展,这个时候持续集成( ...

  9. [转帖]从光刻机的发展,看懂ASML为何是不可取替

    从光刻机的发展,看懂ASML为何是不可取替 http://mini.eastday.com/mobile/171230223351249.html# 2017-12-30 22:33    来源:半导 ...

  10. Redis 集群_主从复制_哨兵模型

    1 redis集群简介 1.1 集群的概念 所谓的集群,就是通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定.高效的状态. 1.1.1 使用redis集群的必要性 问题:我们已经部署好了 ...