关于单点登录的纪要

 

关于多系统的相互登录,连接,通常都考虑到安全问题会把一些信息隐藏起来,我们在这里使用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.oncontextmenu=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>


阅读更多
想对作者说点什么? 我来说一句

关于Java面试的一些纪要

2010年08月19日 145KB 下载

阿里云栖大会纪要

2017年11月12日 301KB 下载

mantis安装要点

2011年05月20日 79KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭