久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

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

JSP登錄中Session的用法實例詳解

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

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

登錄頁面

<%@ 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>賬號:</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>

檢測賬號密碼以及設(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");
 }
 }
 
}

成功登錄頁面

<%@ 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>成功頁面</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>

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

標(biāo)簽: JSP
相關(guān)文章:
主站蜘蛛池模板: 中文字幕一页二页 | 午夜视频福利在线观看 | 日韩精品在线视频观看 | 日韩欧美精品一区二区三区 | 麻豆.蜜桃.91.天美入口 | 龙珠z普通话国语版在线观看 | 国产a级大片 | 国产精品永久久久久久久久久 | 欧美午夜一区二区三区免费大片 | 欧美久久久久 | 成人亚洲精品久久久久 | hd国产人妖ts另类视频 | 99热最新网站 | 成人国产精品一级毛片视频 | 爱爱视频网站 | 亚洲国产精品久久久 | 成人免费视频观看视频 | va在线| 中文在线播放 | 欧美大片一区二区 | www伊人| 欧美精品一区视频 | 久久机热 | 在线观看你懂的视频 | 99在线视频观看 | 欧美 日韩 国产 一区 | 久久国产日韩 | 亚洲国产精品99久久久久久久久 | 免费不卡视频 | 国产成人精品在线 | 国产成人91| www.日本精品 | 国产高清一级毛片在线不卡 | 国产日韩av在线 | 午夜男人的天堂 | 亚洲精品久久一区二区三区 | 女人夜夜春高潮爽a∨片传媒 | 午夜电影av | 日韩视频在线观看不卡 | 国产精品精品久久久 | 50人群体交乱视频 |