程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> JSP權限控制源碼

JSP權限控制源碼

編輯:關於JSP

JSP權限控制源碼


        偶然翻到很多年前,剛學Java的時候學的一段代碼。或許,現在讓寫,還寫不出來了。技術如潮、不進則退。還是年輕好啊,思路清晰、精神充沛。

[java] 
<%@ page contentType="text/html; charset=gb2312" %> 
 
<%@ page import="qlsoft.PWebs.Business.PermitBean" %> 
<jsp: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);  www.2cto.com
        %> 
            <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 <錯誤的頁面請求> 
%> 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved