<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)頁面處理


          日歷

          鏈接

          個人資料

          存檔

          丰满少妇高潮惨叫久久久| 国内精品久久人妻互换| 久久国产视屏| 久久人人爽人人爽人人片AV东京热| 91麻豆国产精品91久久久| 久久精品亚洲日本波多野结衣| 久久er国产精品免费观看2| 久久精品无码专区免费| 亚洲精品tv久久久久久久久| 色综合久久精品中文字幕首页| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久久久久久91精品免费观看| 久久婷婷色综合一区二区| 72种姿势欧美久久久久大黄蕉 | 囯产极品美女高潮无套久久久| 精品久久人妻av中文字幕| 亚洲精品97久久中文字幕无码| 国产亚洲欧美精品久久久| 欧美成a人片免费看久久| 亚洲国产精品久久久久婷婷老年| 亚洲精品成人久久久| 国产2021久久精品| 东京热TOKYO综合久久精品| 伊人久久大香线蕉精品不卡| 热re99久久精品国产99热| 久久精品亚洲中文字幕无码麻豆| 亚洲v国产v天堂a无码久久| 国产激情久久久久影院老熟女免费 | 欧美喷潮久久久XXXXx| 亚洲国产精品成人久久蜜臀| 久久精品国产亚洲综合色| 麻豆亚洲AV永久无码精品久久| 久久久久亚洲AV无码专区桃色| 亚洲国产成人久久精品影视| 亚洲精品乱码久久久久久自慰| yy6080久久| 亚洲va久久久噜噜噜久久天堂| 久久久久se色偷偷亚洲精品av | 一个色综合久久| 久久久久久综合网天天| 热99RE久久精品这里都是精品免费 |