欧美videos另类精品-欧美videos另类极品-欧美vide-欧美va在线视频-欧美va在线观看-欧美va在线播放免费观看

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

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

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

主要說明2個(gè)對象,request,session

1、request 對象

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

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

2、session 對象

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

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



二.表單提交

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



三.驗(yàn)證跳轉(zhuǎn)

當(dāng)form提交信息后交給check.jsp驗(yàn)證,使用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>驗(yàn)證</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>



五.注意事項(xiàng)

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


日歷

鏈接

個(gè)人資料

存檔

主站蜘蛛池模板: 精品一区二区三区高清免费不卡 | 欧美一级片观看 | 91成人爽a毛片一区二区 | 亚洲免费视频播放 | 九色PORNY真实丨国产大胸 | 美国玩尿眼道videos | 5g影院天天影院天天爽影院网站 | 欧美一区二区不卡视频 | 五月色综合婷婷综合俺来也 | 国产精品99久久 | 毛片在线免费视频 | 全日爱韩国视频在线观看 | 91视频破解 | 任你操视频在线观看 | 亚洲性爱区 | 色综合视频一区二区三区 | 丝袜捆绑调教视频免费区 | 国产农村一一级特黄毛片 | 国产一区二 | 美女脱一净二净不带胸罩 | 国产日本免费 | 亚洲国产成人精品无码区5566 | 国产精品亚洲一区二区 | 久久青青草视频在线观 | a性片| 亚洲羞羞裸色私人影院 | 美女被草出水 | 男人操美女逼视频 | 亚洲 激情| fulao在线观看的 | 欧美午夜视频一区二区 | 423hk四虎| 亚洲免费国产 | 单身男女韩剧在线看 | 韩国三级视频网站 | 日韩精品视频福利资源站 | 精品国产自在现线久久 | 精品国产中文字幕在线视频 | 国产动作大片 | 香蕉国产人午夜视频在线观看 | 人阁色第四影院在线观看 |