国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

JSP登錄中Session的用法實(shí)例詳解

瀏覽:7日期:2022-06-07 13:24:59

本文實(shí)例講述了JSP登錄中Session的用法。分享給大家供大家參考,具體如下:

登錄頁(yè)面

<%@ page language="java" contentType="text/html; charset=utf-8"
  pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
 <div>
 <form action="IndexServlet" method="post">
 <div>
  <div>賬號(hào):</div><input type="text" name="user"/>
 </div>
 <div>
  <div>密碼:</div><input type="text" name="password"/>
 </div>
 <div>
  <input type="submit" name="ok" value="登錄"/>
 </div>
 </form>
 </div>
</body>
</html>

檢測(cè)賬號(hào)密碼以及設(shè)置session的IndexServlet

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
    
  /**
   * @see HttpServlet#HttpServlet()
   */
  public IndexServlet() {
    super();
    // TODO Auto-generated constructor stub
  }
 
 /**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 // TODO Auto-generated method stub
 response.getWriter().append("Served at: ").append(request.getContextPath());
 }
 
 /**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 // TODO Auto-generated method stub
 request.setCharacterEncoding("utf-8");
 String user = request.getParameter("user");
 String password = request.getParameter("password");
 
 String path = request.getContextPath();
 HttpSession session=request.getSession();
 
 if ("1".equals(user) && "1".equals(password)) {
  
  session.setAttribute("name", user);
  response.sendRedirect(path + "/success.jsp");
  
 }else{
  response.sendRedirect(path + "/Index.jsp");
 }
 }
 
}

成功登錄頁(yè)面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
 String path = request.getContextPath();
%>
<%
 Object name = session.getAttribute("name");
 if(name==null){
 response.sendRedirect(path+"/Index.jsp");
 }
%>
<html>
 <head>
 <title>成功頁(yè)面</title>
 </head>
 <body>
 恭喜你,騷年,<%=session.getAttribute("name") %>,成功登陸了!
 <a href="out.jsp" rel="external nofollow" >注銷</a>
 </body>
</html>

注銷功能的jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 <% 
 String path = request.getContextPath();
 %>
 <%
   session.removeAttribute("name");
   response.sendRedirect(path+"/Index.jsp");
  %>
</body>
</html>

希望本文所述對(duì)大家jsp程序設(shè)計(jì)有所幫助。

標(biāo)簽: JSP
相關(guān)文章:
主站蜘蛛池模板: 国产成人精品高清免费 | 国产成人亚洲毛片 | 欧美人禽杂交狂配毛片 | 女人一级一级毛片 | 韩国一大片a毛片 | 曰本女同互慰高清在线观看 | 亚洲性xx | 自拍在线| 日韩 亚洲 制服 欧美 综合 | 亚洲国产99在线精品一区二区 | 国产亚洲欧美日韩综合综合二区 | 免费一级特黄 | 美女白浆视频 | 免费公开视频人人人人人人人 | 欧美精品一区视频 | 欧美午夜视频一区二区三区 | 国产精品高清在线 | a级毛片免费全部播放 | 色噜噜国产精品视频一区二区 | 一级做a爱片久久毛片 | 久草在线视频资源 | 久草在线新视觉 | 免费看成人播放毛片 | 91视频啪啪 | 玖玖精品 | 草草影院永久在线观看 | 中文国产成人精品久久久 | 国产v日韩v欧美v精品专区 | 日本www色视频成人免费网站 | ⅹxx中国xxx人妖 | 国产综合在线观看视频 | 久久高清免费视频 | 精品欧美一区二区在线看片 | 国产精品女在线观看 | 男女在线视频 | 人碰人碰人成人免费视频 | 韩国一级毛片视频 | 国产成人午夜性视频影院 | 黄性色 | 欧美在线区 | 欧美成人毛片 |