<em id="09ttv"></em>
    <sup id="09ttv"><pre id="09ttv"></pre></sup>
    <dd id="09ttv"></dd>

        • 簡單的驗證跳轉(zhuǎn)

          2020-3-6    seo達(dá)人

          一.有關(guān)于內(nèi)置對象的作用域

          主要說明2個對象,request,session

          1、request 對象

          request 對象是 javax.servlet.httpServletRequest類型的對象。 該對象代表了客戶端的請求信息,主要用于接受通過HTTP協(xié)議傳送到服務(wù)器的數(shù)據(jù)。(包括頭信息、系統(tǒng)信息、請求方式以及請求參數(shù)等)。

          request只在2個頁面之間傳遞,每一次新的請求都會新建一個request對象,也就是說可能會request對象不一致導(dǎo)致空指針異常。

          2、session 對象

          session 對象是由服務(wù)器自動創(chuàng)建的與用戶請求相關(guān)的對象。服務(wù)器為每個用戶都生成一個session對象,用于保存該用戶的信息,跟蹤用戶的操作狀態(tài)。session對象內(nèi)部使用Map類來保存數(shù)據(jù),因此保存數(shù)據(jù)的格式為 “Key/value”。 session對象的value可以使復(fù)雜的對象類型,而不僅僅局限于字符串類型。

          session對象在整個會話只有一個,也就是說session對象的數(shù)據(jù)會一直保留直到主動進(jìn)行數(shù)據(jù)更改。



          二.表單提交

          在index.jsp中使用form進(jìn)行數(shù)據(jù)的提交,action的目標(biāo)是check.jsp,method是post



          三.驗證跳轉(zhuǎn)

          當(dāng)form提交信息后交給check.jsp驗證,使用getParameter來得到form的信息,并使用setAttribute保存。在check.jsp中判斷賬號密碼是否正確后,使用



          <jsp:forward page=".jsp"></jsp:forward>

          1

          進(jìn)行跳轉(zhuǎn),
          .jsp是想要跳轉(zhuǎn)的頁面路徑。



          四.詳細(xì)代碼

          index.jsp



          <%@ page language="java" import="java.util." pageEncoding="UTF-8"%>

          <%

          String path = request.getContextPath();

          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

          %>



          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

          <html>

            <head>

              <base href="<%=basePath%>">

              

              <title>登陸</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">

          -->



            </head>

            

            <body>



             <form action="check.jsp" method="post">

          請輸入用戶名:

          <input type = "text" name = "username"><br/>

          請輸入密碼:

          <input type = "password" name = "passwd"><br/>

          <input type="submit" name="submit" value="登錄">

          </form>

           

            </body>

          </html>





          check.jsp



          <%@ page language="java" import="java.util.
          " pageEncoding="UTF-8"%>

          <%

          String path = request.getContextPath();

          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

          %>



          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

          <html>

            <head>

              <base href="<%=basePath%>">

              

              <title>驗證</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">

          -->



            </head>

            

            <body>

             

          <%

            String username = (String)request.getParameter("username");

            String passwd = (String)request.getParameter("passwd");

            request.setAttribute("username", username);

            request.setAttribute("passwd", passwd);

           

            if(username.equals("admin")&&passwd.equals("123")){

          %>

          <jsp:forward page="succeed.jsp"></jsp:forward> 

          <%}else{ %>

          <jsp:forward page="failed.jsp"></jsp:forward> 

          <%} %>

            </body>

          </html>



          succeed.jsp



          <%@ page language="java" import="java.util." pageEncoding="UTF-8"%>

          <%

          String path = request.getContextPath();

          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

          %>



          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

          <html>

            <head>

              <base href="<%=basePath%>">

              

              <title>登陸成功</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">

          -->



            </head>

            

          <body>

          <% 

          String username = (String)request.getAttribute("username");

          String passwd = (String)request.getAttribute("passwd");



          %>

          <%=username %>登陸成功



          </body>

          </html>



          failed.jsp



          <%@ page language="java" import="java.util.
          " pageEncoding="UTF-8"%>

          <%

          String path = request.getContextPath();

          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

          %>



          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

          <html>

            <head>

              <base href="<%=basePath%>">

              

              <title>登陸失敗</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">

          -->



            </head>

          <body>

          <% 

          String username = (String)request.getAttribute("username");

          String passwd = (String)request.getAttribute("passwd");



          %>

          <%=username %>登陸失敗

          </body>

          </html>



          五.注意事項

          在jsp中使用form提交表單不能直接進(jìn)行跳轉(zhuǎn),否則操作不慎就容易出現(xiàn)空指針異常,建議交由單獨(dú)的跳轉(zhuǎn)頁面處理


          日歷

          鏈接

          個人資料

          藍(lán)藍(lán)設(shè)計的小編 http://www.sdgs6788.com

          存檔

          久久久久亚洲av无码专区导航| 免费精品国产日韩热久久| 亚洲中文字幕无码久久2020| 99久久婷婷国产综合亚洲| 日本道色综合久久影院| 亚洲精品乱码久久久久久中文字幕 | 久久久久高潮综合影院| 亚洲乱亚洲乱淫久久| 亚洲乱码精品久久久久..| 97久久精品国产精品青草| 久久久久久久久久久久久久| 久久精品99久久香蕉国产色戒 | 国产精品成人久久久久久久| 麻豆成人久久精品二区三区免费| 精品国产热久久久福利| 久久综合综合久久狠狠狠97色88| 久久影院午夜理论片无码| 精品水蜜桃久久久久久久| 性欧美大战久久久久久久久| 国产精品伊人久久伊人电影 | 亚洲一区精品伊人久久伊人 | 88久久精品无码一区二区毛片| 亚洲а∨天堂久久精品9966| 色婷婷狠狠久久综合五月| 精品免费tv久久久久久久| 久久99国产精一区二区三区| 久久久久亚洲AV无码观看| 精品久久久久久久久久久久久久久| 久久天天躁狠狠躁夜夜96流白浆| 婷婷久久五月天| 四虎国产精品免费久久久| 久久综合九色综合欧美狠狠| 久久国产色AV免费看| 久久久久亚洲精品无码蜜桃| 久久精品国产清自在天天线| 亚洲精品无码久久久| 久久国产乱子伦精品免费午夜| 香港aa三级久久三级老师2021国产三级精品三级在 | 成人午夜精品久久久久久久小说| 色婷婷综合久久久久中文| 777午夜精品久久av蜜臀|