jsp 中登入驗證 登出 的模版

來源:互聯網
上載者:User

標籤:

  • 使用者名稱密碼驗證模版
  •  
 <%@page import="com.jerehedu.bao.User"%><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%    //擷取一個使用者    User user=(User)session.getAttribute("user"); %><%     String uname=request.getParameter("uname");    String upwd=request.getParameter("upwd");    if(uname!=null&&!uname.equals("")&&upwd!=null&&!upwd.equals("")) {        //建立一個user對象        user=new User(uname,upwd);        session.setAttribute("user", user);    }%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP ‘ch0402.jsp‘ starting page</title>        <meta http-equiv="pragma" content="no-cache">    <meta http-equiv="cache-control" content="no-cache">    <meta http-equiv="expires" content="0">        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    <meta http-equiv="description" content="This is my page">    <!--    <link rel="stylesheet" type="text/css" href="styles.css">    -->    <script type="text/javascript">        /*        *驗證使用者名稱或密碼是否填寫        */        function check(){            var uname=document.getElementById(‘uname‘).value;            var upwd=document.getElementById(‘upwd‘).value;            if(uname==‘‘) {                alert(‘請填寫使用者名稱‘);                return false;            } else if(upwd==‘‘) {                alert(‘請填寫密碼‘);                return false;            }        }    </script>  </head>    <body>      <form action="login1.jsp" onsubmit="return check()" method="post">        <table>            <tr>                <td>使用者名稱:</td>                <td>                    <input type="text" name="uname" id="uname" value="" />                </td>            </tr>            <tr>                <td>密碼:</td>                <td>                    <input type="password" name="upwd" id="upwd" value="" />                </td>            </tr>            <tr>                <td>                    <input type="submit" value="登入" />                </td>            </tr>            <% if(user!=null&&!(user.getUserName().equals("admin")&&user.getPassword().equals("123456"))) {            %>            <tr>                <td colspan="2">                    使用者名稱或密碼錯誤                </td>            </tr>            <%                        } else if(user!=null){                response.sendRedirect("welcome.jsp");            }             %>        </table>      </form>  </body> 
  • 登出1:
  •  <body>   歡迎您: <%=session.getAttribute("user").toString() %>   <a href="Day5_1_zhuxiao.jsp">登出</a>  </body>  
 
  • 登出2:
  •   <body>    <%        session.invalidate();        response.sendRedirect("Day5_1.jsp");        //response.addHeader("refresh","2; URL=Day5_1.jsp");         %>     您已登出  </body> 
  • 清Null 物件
  •     <%          //把session對象清空          session.invalidate();          response.sendRedirect("login.jsp");       %>  

jsp 中登入驗證 登出 的模版

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.