午夜勾魂曲-午夜福利自怕-午夜福利在线观看6080-午夜福利院电影-国产精品毛片AV久久97-国产精品麻豆高潮刺激A片

簡單的驗證跳轉

2020-3-6    seo達人

一.有關于內置對象的作用域

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

1、request 對象

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

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

2、session 對象

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

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



二.表單提交

在index.jsp中使用form進行數據的提交,action的目標是check.jsp,method是post



三.驗證跳轉

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



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

1

進行跳轉,
.jsp是想要跳轉的頁面路徑。



四.詳細代碼

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提交表單不能直接進行跳轉,否則操作不慎就容易出現空指針異常,建議交由單獨的跳轉頁面處理


日歷

鏈接

個人資料

藍藍設計的小編 http://m.gerard.com.cn

存檔

主站蜘蛛池模板: 国产精品无码久久av | 美女网站免费久久久久久久 | 中文字幕在线观看网址 | 国产精品久久人妻互换毛片 | 好姑娘BD高清在线观看免费 | 天堂Av亚洲欧美日韩国产综合 | 木凡的天空在线收听 | 久久视热频国只有精品 | 国产一级毛片在线 | 天天射天天爱天天干 | 激情男女高潮射精AV免费 | 素人约啪第五季 | 亚洲精品天堂无码中文字幕影院 | 自拍偷拍12p| 国产成人精品男人的天堂网站 | 精品无人区麻豆乱码1区2 | 同居了嫂子在线观看 | 伊人网综合| 高H辣肉办公室 | 91视频18| 国产学生无码中文视频一区 | 美国一级大黄一片免费的网站 | 日韩精品AV一区二区三区 | YELLOW日本动漫高清免费 | 亚洲国产货青视觉盛宴 | 苍井空小公主qvod | 国产成人精品永久免费视频 | 91精品婷婷国产综合久久8 | 国产亚洲视频在线观看 | 久久亚洲精品AV成人无 | 国产精品AV无码免费播放 | 欧美色妞AV重囗味视频 | 97精品国偷拍自产在线 | 99国产精品人妻无码免费 | 穿白丝袜边走边尿白丝袜 | 国产午夜a理论毛片在线影院 | 2022国产91精品久久久久久 | 午夜伦理yy44008影院 | 一本大道熟女人妻中文字幕在线 | 99免费在线 | 全彩黄漫火影忍者纲手无遮挡 |