当前位置:网站首页>WEB网站登录系统

WEB网站登录系统

2020-12-08 09:03:41 程序猿欧文

写了这么多年的网站了,登录系统用了好几种了,有自己实现的,有spring security的,有apache shiro的,但其实原理都是一样,session加cookie实现的。  

登录页面login.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Insert title here</title></head><body> <form name="loginForm" method="post" action="login">   <table border="0px">    <tr>     <td>姓名:</td>     <td><input name="username" value=""></input></td>    </tr>    <tr>     <td>密码:</td>     <td><input name="passwd"></input></td>    </tr>    <tr>     <td><input type="checkbox" name="remeberme" value="remeberme">记住我</input> </td>    </tr>    <tr>     <td></td>     <td><input type="submit" class="loginform" name="submit"      value="确定">&nbsp; <input type="button" class="loginform"      name="submit" value="取消"></td>    </tr>   </table>  </form></body></html>

 

login servlet:

package my.authentication.normal;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;/** * Servlet implementation class login */@WebServlet("/login")public class login extends HttpServlet { private static final long serialVersionUID = 1L;   /**  * @see HttpServlet#HttpServlet()  */ public login() {  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  //doGet(request, response);  HttpSession session= request.getSession();  String username= request.getParameter("username");  String remeberme=request.getParameter("remeberme");  if(remeberme!=null)  {   System.out.println(remeberme);  }  else  {   System.out.println("没有选中remeberme");  }  if(username.equals("yl"))  {   session.setAttribute("user", username);      if(remeberme!=null)   {    Cookie ck=new Cook.........

版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4780411