前端POST跳转/窗口打开(1)

<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="java.security.SecureRandom"%>
<%@page import="javax.crypto.Cipher"%>
<%@page import="javax.crypto.SecretKey"%>
<%@page import="javax.crypto.SecretKeyFactory"%>
<%@page import="javax.crypto.spec.DESKeySpec"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<script language=javascript src="jquery.js"></script>
<title></title>
</head>
    
    <%!
        private  static String DES = "DES"; 
        private static  String PASSWORD_CRYPT_KEY = "xbandfamily";

        public  static String decrypt(String data) {
        try {
            return new String(decrypt(hex2byte(data.getBytes()),
                    PASSWORD_CRYPT_KEY.getBytes()));
        } catch (Exception e) {
        }
        return null;
    }
        public static byte[] hex2byte(byte[] b) {
        if ((b.length % 2) != 0)
            throw new IllegalArgumentException("长度不是偶数");
        byte[] b2 = new byte[b.length / 2];
        for (int n = 0; n < b.length; n += 2) {
            String item = new String(b, n, 2);
            b2[n / 2] = (byte) Integer.parseInt(item, 16);
        }
        return b2;
    }
    
    
        public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
        // DES算法要求有一个可信任的随机数源
        SecureRandom sr = new SecureRandom();
        // 从原始密匙数据创建一个DESKeySpec对象
        DESKeySpec dks = new DESKeySpec(key);
        // 创建一个密匙工厂,然后用它把DESKeySpec对象转换成
        // 一个SecretKey对象
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
        SecretKey securekey = keyFactory.generateSecret(dks);
        // Cipher对象实际完成解密操作
        Cipher cipher = Cipher.getInstance(DES);
        // 用密匙初始化Cipher对象
        cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
        // 现在,获取数据并解密
        // 正式执行解密操作
        return cipher.doFinal(src);
    }


         //String usercode = nc.uap.lfw.core.LfwRuntimeEnvironment.getLfwSessionBean().getUser_code();
         

    %>
    <%String usercode = decrypt(request.getParameter("usercode"));%>
<body>
    <script>
         $.ajax({  
            url:"https://finereport.rfchina.com:10081/WebReport/ReportServer?op=fs_load&cmd=sso",//单点登录的管理平台报表服务器  
            dataType:"jsonp",//跨域采用jsonp方式  
            data:{"fr_username":"<%=usercode%>","fr_password":"rfchina38882777"},//获取用户名密码  
            jsonp:"callback",  
            timeout:5000,//超时时间(单位:毫秒)  
            success:function(data) {  
              if (data.status === "success") { 
                //window.open(data.url);//认证成功跳转页面,因为ajax不支持重定向所有需要跳转的设置 
                //登录成功     
                window.top.location.href = data.url; 
              } else if (data.status === "fail"){  
                alert("用户名或密码错误");//登录失败(用户名或密码错误)  
              }  
            },  
            error:function(){  
            alert("超时或服务器其他错误");// 登录失败(超时或服务器其他错误)  
            }  
        });

    </script>
</body>
</html>

发布了81 篇原创文章 · 获赞 0 · 访问量 707

猜你喜欢

转载自blog.csdn.net/weixin_42699486/article/details/96975142