歡迎您光臨本站 註冊首頁

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

←手機掃碼閱讀     zhang3221994 @ 2020-06-12 , reply:0

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

登錄頁面

    Insert title here賬號:密碼:

 

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

 

成功登錄頁面

        成功頁面恭喜你,騷年,,成功登陸了!   註銷

 

註銷功能的jsp

    Insert title here

 

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

                                                     

   


[zhang3221994 ] JSP登錄中Session的用法實例詳解已經有135次圍觀

http://coctec.com/docs/javascript/show-post-238178.html