当前位置:网站首页>Cookie setting three-day secret free login (run tutorial)
Cookie setting three-day secret free login (run tutorial)
2022-07-06 11:14:00 【Call me uncle】
Catalog
1. What is? cookie
Cookie It is a small piece of information sent by the server to the user's browser and kept locally , It will be carried and sent to the server the next time the browser sends a request to the server . Usually , It is used to tell the server whether two requests are from the same browser .
2.cookie Password free login
Login screen login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<body onload="get()">
<form action="/JiuYueServices/login" method="get">
user name :<input type="text" name="username"/>
password :<input type="text" name="password"/>
<input type="submit" value=" Sign in ">
</form>
</body>
<script>
function get(){
var flge = getCookie("flge");
if(flge!=""){
alert(" Welcome to visit again ");
}
}
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
}
return "";
}
</script>
</html>
LoginServlet.java
package com.qcby.servlet;
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;
@WebServlet("/login")
public class LoginServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1. Server creation cookie object
String username = req.getParameter("username");
String password = req.getParameter("password");
System.out.println(username +" " +password);
Cookie cookie = new Cookie("flge", "qcby");
//2. Set up cookie The period of validity 1 Hours
cookie.setMaxAge(3 * 24 * 60*60); // There are three ways to store data :>0 The period of validity , Unit second ;=0 Browser closed ;<0 Temporary storage , The default is -1
//3. take cookie Respond to clients
resp.addCookie(cookie);
}
}
function :http://localhost:8080/JiuYueServices/login.html
Back out , Log in again http://localhost:8080/JiuYueServices/login.html
success !!!
3.cookie Advantages and disadvantages
advantage :
- Configurable expiration rules
- simplicity :cookie Is a lightweight structure that contains text , Contains simple key value pairs
- Data persistence :cookie By default, it can be saved on the client browser until it expires
shortcoming :
- Size is limited : Most browsers are right cookie There is a limit to the size of , Namely 4k and 8k byte
- The user is configured to disable : Some users disable the browser or client device to receive cookie The ability of , So it limits this function
- Potential security risks :Cookie May be tampered with
边栏推荐
- When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
- AcWing 179.阶乘分解 题解
- Software testing - interview question sharing
- Armv8-a programming guide MMU (2)
- Database advanced learning notes -- SQL statement
- [C language foundation] 04 judgment and circulation
- Attention apply personal understanding to images
- C language advanced pointer Full Version (array pointer, pointer array discrimination, function pointer)
- Have you mastered the correct posture of golden three silver four job hopping?
- QT creator specifies dependencies
猜你喜欢
Knowledge Q & A based on Apache Jena
[recommended by bloggers] C # generate a good-looking QR code (with source code)
[Thesis Writing] how to write function description of jsp online examination system
Did you forget to register or load this tag 报错解决方法
02-项目实战之后台员工信息管理
AcWing 1298.曹冲养猪 题解
【博主推荐】SSM框架的后台管理系统(附源码)
Why can't I use the @test annotation after introducing JUnit
软件测试与质量学习笔记3--白盒测试
Copie maître - esclave MySQL, séparation lecture - écriture
随机推荐
软件测试-面试题分享
@controller,@service,@repository,@component区别
JDBC原理
C language advanced pointer Full Version (array pointer, pointer array discrimination, function pointer)
AcWing 179.阶乘分解 题解
CSDN markdown editor
数据库高级学习笔记--SQL语句
Esp8266 at+cipstart= "", "", 8080 error closed ultimate solution
Kubernetes - problems and Solutions
解决安装Failed building wheel for pillow
Software testing and quality learning notes 3 -- white box testing
Data dictionary in C #
Windows下安装MongDB教程、Redis教程
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application
MySQL完全卸载(Windows、Mac、Linux)
Remember a company interview question: merge ordered arrays
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
Swagger、Yapi接口管理服务_SE
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)
Software testing - interview question sharing