关于单点登录的纪要

 

关于多系统的相互登录,连接,通常都考虑到安全问题会把一些信息隐藏起来,我们在这里使用servlet的方式封装

再在页面上使用post方式进行提交登陆,使用get方式会存在一些问题,比如编码规则不一致(其他忘记了,当时没有记录)

 

package  servlets;

import  java.io.IOException;
import  java.io.PrintWriter;

import  javax.servlet.Servlet;
import  javax.servlet.ServletException;
import  javax.servlet.http.HttpServlet;
import  javax.servlet.http.HttpServletRequest;
import  javax.servlet.http.HttpServletResponse;
import  javax.servlet.http.HttpSession;

import  com.sac.common.bean.UserData;

public   class  PjLogin  extends  HttpServlet  implements  Servlet  {
    
/* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     
*/

    
public PjLogin() {
        
super();
    }


    
/* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0, HttpServletResponse arg1)
     
*/

    
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {

    }


    
/* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest arg0, HttpServletResponse arg1)
     
*/

    
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
        arg1.setHeader(
"Pragma""No-cache");
        arg1.setHeader(
"Cache-Control""no-cache");
        arg1.setHeader(
"Expires""0");
        
        arg1.setHeader(
"Content-Type","text/html; charset=GBK");
        arg1.setCharacterEncoding(
"UTF-8");
        arg0.setCharacterEncoding(
"GBK");
        
        PrintWriter out 
= arg1.getWriter();
        String type 
= arg0.getParameter("type");
        HttpSession session 
= arg0.getSession();
        Object obj 
= session.getAttribute("pjcode");
        String pjcode 
= obj==null?"":obj.toString();
        String dcode 
= arg0.getParameter("dcode");
        
        UserData userData
=(UserData)arg0.getSession().getAttribute("userData");//获取用户信息
        
        
if(type != null && obj != null && dcode != null && pjcode.equals(dcode)){
            
if(type.equals("type1")){
                String t_gysId 
= arg0.getParameter("gysId");
                String gysid 
= t_gysId==null?"":t_gysId;//供应商名称
                System.out.println("供应商名称:"+gysid);
                out.println(
"<form name='form1' action='http://211.103.190.84:8000/hdgys/PGSuppevaluscoreListExt.action' method='post'>");
                out.println(
"<input type='hidden' name='username' value='dccs'>");
                out.println(
"<input type='hidden' name='password' value='PU8r8H3BvjiyDNbkaUmhBx+dDj0='>");
//                System.err.println(gysid);
                out.println("<input type='hidden' name='f_companyname' value='" + gysid + "'>");
                out.println(
"</form>");
                out.println(
"<script>form1.submit();</script>");
            }
else if(type.equals("type2")){                
                out.println(
"<form name='form1' action='http://211.103.190.84:8000/hdgys/LoginSuccess.action' method='post'>");
                
if(userData!=null){
                out.println(
"<input type='hidden' name='username' value='"+userData.getLgnm()+"'>");
                System.err.println(userData.getLgnm());
                out.println(
"<input type='hidden' name='password' value='"+userData.getPjpwd()+"'>");
                System.err.println(userData.getPjpwd());
                }

                out.println(
"</form>");
                out.println(
"<script>form1.submit();</script>");                
            }
else if(type.equals("type3")){
                out.println(
"<form name='form1' action='http://211.103.190.84:8000/hdgys/PESuppBlacklistList.action' method='post'>");
                out.println(
"<input type='hidden' name='username' value='dccs'>");
                out.println(
"<input type='hidden' name='password' value='PU8r8H3BvjiyDNbkaUmhBx+dDj0='>");
                out.println(
"</form>");
                out.println(
"<script>form1.submit();</script>");                
            }
else if(type.equals("type4")){
                out.println(
"<form name='form1' action='http://211.103.190.84:8000/hdgys/PCSuppclassActiveInfoListTree.action' method='post'>");
                out.println(
"<input type='hidden' name='username' value='dccs'>");
                out.println(
"<input type='hidden' name='password' value='PU8r8H3BvjiyDNbkaUmhBx+dDj0='>");
                out.println(
"</form>");
                out.println(
"<script>form1.submit();</script>");                
            }

        }

    }


}

 

jsp页面的使用:

 

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<% @ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<% @ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<% @taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<% @page import="com.sac.common.Pub"  %>
< html:html >
< HEAD >
<% @ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK" %>
< META  http-equiv ="Content-Type"  content ="text/html; charset=GBK" >
< META  name ="GENERATOR"  content ="IBM Software Development Platform" >
< META  http-equiv ="Content-Style-Type"  content ="text/css" >
< LINK  href ="<%=request.getContextPath() %>/theme/Master.css"  rel ="stylesheet"  type ="text/css" >
< base  target ="mainFrame" >
< TITLE > test </ TITLE >
< script  language ="JavaScript" >
//document.οncοntextmenu=new Function("event.returnValue=false;");//屏蔽右键
//
document.onselectstart=new Function("event.returnValue=false;");//屏蔽选择

</ script >

</ HEAD >
< bean:define  id ="value"  name ="userMenu"  property ="ofgpfgnu" />
< BODY  topmargin ="0"  leftmargin ="0"    >
< form  name ="pjform"  action ="<%=request.getContextPath()%>/pjLogin"  method ="post"  target ="_blank" >
< input  type ="hidden"  name ="type"  value ="" >
<%
String pjcode = Pub.createRan();
String css="";
session.setAttribute(
"pjcode",Pub.createRan());
%>
< input  type ="hidden"  name ="dcode"  value ="<%=pjcode%>" >
</ form >
<% -- 左侧菜单开始 -- %>
< div  style =width:160;height:450;background:#daf1f7 >
< TABLE  cellSpacing =0  cellPadding =0  width =160  border =0  >
    
< TBODY >
            
< class =white2     href ="#"  onClick ="pjform.type.value='type4';pjform.submit();return false;" > &nbsp;&nbsp;&nbsp; 登录4 </ A >
            
< class =white2     href ="#"  onClick ="pjform.type.value='type2';pjform.submit();return false;" > &nbsp;&nbsp;&nbsp; 登录2 </ A >
            
< class =white2     href ="#"  onClick ="pjform.type.value='type3';pjform.submit();return false;" > &nbsp;&nbsp;&nbsp; 登录3 </ A >
</ TBODY >
</ TABLE >< div  style ='LEFT:0;WIDTH:160;POSITION:absolute;TOP:446;height:11;' >  
  
< table  width ="100%"  height ="11"  border ="0"  cellpadding ="0"  cellspacing ="0" >
        
< tr >< td >< img  src ="<%=request.getContextPath()%>/images/hn-left_r7_c1.gif"  width ="160"  height ="11"   /></ td ></ tr ></ table ></ div ></ div >
<% -- 左侧菜单结束 -- %>
< noscript >
< iframe  src ="nosaveas.html"  style ="display:none" ></ iframe >
</ noscript >
</ BODY >
</ html:html >


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值