欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JSP权限控制源码

程序员文章站 2022-05-30 13:57:15
jsp权限控制         偶然翻到很多年前,刚学java的时候学的一段代码。或许,现在让写,还写不出来了。技术如潮、不进...

jsp权限控制


        偶然翻到很多年前,刚学java的时候学的一段代码。或许,现在让写,还写不出来了。技术如潮、不进则退。还是年轻好啊,思路清晰、精神充沛。

[java] 
<%@ page contenttype="text/html; charset=gb2312" %> 
 
<%@ page import="qlsoft.pwebs.business.permitbean" %> 
<:usebean id="permitbean" scope="session" class="qlsoft.pwebs.business.permitbean" /> 
<%@ page import="qlsoft.pwebs.business.memberbean" %> 
<jsp:usebean id="memberbean" scope="session" class="qlsoft.pwebs.business.memberbean" /> 
<% 
    string action= request.getparameter("action"); 
%> 
        <script language="javascript"> 
            //alert("permit request action:" + "<%=action%>"); 
        </script> 
    <% 
    if("login".equalsignorecase(action)) 
    {//会员登录:验证用户身份,并设置session变量及已登录标志 
        //获取登录参数 
        string username= request.getparameter("username"); 
        string userpwd= request.getparameter("password"); 
        system.out.println("帐号:" + username + "密码:" + userpwd); 
        if(username == null || username == "" || userpwd == null || userpwd == "") 
        {//请求的参数无效 
    %> 
        <script language="javascript"> 
            alert("没有会员登录必须的请求参数!"); 
            window.history.go(-1); 
        </script> 
    <% 
        } 
        else 
        {//参数有效 
            if(permitbean.memberlogin(username,userpwd)) 
            {//登录成功 
                //chengxiaoxu 2004-05-25 remark code in here to best 
                session.setattribute("sessionpermit",permitbean); 
                permitbean ssnpermit = (permitbean)session.getattribute("sessionpermit"); 
                 
                string strlogin = ssnpermit.getislogin() ? "登录成功!" : "登录失败???"; 
                string ackname = ssnpermit.getmgrackname(); 
                system.out.println("会员帐号:" + strlogin + "\n" + ackname); 
                if(memberbean.getbeaninfobyid(ssnpermit.getmemberid())) 
                { 
                    system.out.println("提取会员信息成功!"); 
                    session.setattribute("sessionmember",memberbean); 
                } 
                 
        %> 
            <script language="javascript"> 
                //alert("<%=strlogin %>"); 
                //alert("<%=permitbean.getmsg() %>"); 
                //window.target="_blank"; 
                //此处完成后应该是会员管理中心主页面 
                window.location="membermain.jsp"; 
            </script> 
        <% 
            } 
            else 
            {//登录失败 
        %> 
            <script language="javascript"> 
                alert("<%=permitbean.getmsg() %>"); 
                window.history.go(-1); 
            </script> 
        <% 
            }//end of <登录失败> 
        }//end of <参数有效> 
    %> 
<% 
    }//end of <会员登录> 
    else if("update".equalsignorecase(action)) 
    {//修改会员密码 
      //获取修改参数 
      string oldpwd= request.getparameter("oldpassword"); 
      string newpwd= request.getparameter("newpassword1"); 
      if(oldpwd == null || oldpwd == "" || newpwd == null || newpwd == "") 
      {//请求的参数无效 
    %> 
            <script language="javascript"> 
                alert("没有资料修改必须的请求参数!"); 
                window.history.go(-1); 
            </script> 
    <% 
        }//end of <请求的参数无效> 
        else 
        {//参数有效 
        %> 
            <% 
            boolean isok = permitbean.changepassword((string)session.getattribute("sessionuseraccount"),oldpwd,newpwd); 
        %> 
            <script language="javascript">alert("<%=permitbean.getmsg() %>");</script> 
      <% 
          if(isok) 
                {//修改成功 
            %> 
                <script language="javascript">window.location="membermain.jsp";</script> 
            <% 
                } 
              else{//修改失败 
            %> 
                <script language="javascript">window.history.go(-1);</script> 
            <% 
                } 
 
        }//end of <参数有效> 
        %> 
<% 
    }//end of <修改会员密码> 
    else if("logout".equalsignorecase(action)) 
    {//会员注销:清空session变量及已登录标志 
        //chengxiaoxu 2004-05-25 update code in here to best 
        if(permitbean != null) 
            permitbean.memberlogout(); 
        session.setattribute("sessionpermit",null); 
        session.setattribute("sessionmember",null); 
        permitbean ssnpermit = (permitbean)session.getattribute("sessionpermit"); 
        string strlogin = ssnpermit==null ? "注销成功!" : "注销失败???"; 
 
%> 
        <script language="javascript"> 
            //alert("<%=strlogin %>"); 
            window.location="main.jsp"; 
        </script> 
<% 
    } 
    else 
    {//错误的页面请求 
%> 
        <script language="javascript"> 
        alert("无效的页面请求"); 
      window.history.go(-1); 
    </script> 
<% 
    }//end of <错误的页面请求> 
%>