亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

用Cookie實現一天免登錄功能

發布時間:2020-07-08 22:16:34 來源:網絡 閱讀:773 作者:Bighead0829 欄目:開發技術

Servlet程序:

package com.westos.untitle2;

import com.westos.untitle2.CityService.UserService;
import com.westos.untitle2.bean.User;

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 java.io.IOException;
import java.util.List;

@WebServlet(name = "Cookie4Servlet")
public class Cookie4Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         response.setCharacterEncoding("utf-8");
         request.setCharacterEncoding("utf-8");
         response.setContentType("text/html;charset=utf-8");
         String username=request.getParameter("username");
         String password=request.getParameter("password");
         UserService userService=new UserService();
         List<User> list=userService.setUser();
         if (username==null||password==null){
            Cookie[] cookie=request.getCookies();
            for (Cookie c:cookie){
                if(c.getName().equals("username")){
                    username=c.getValue();
                }else if(c.getName().equals("password")){
                    password=c.getValue();
                }
            }
        }
        if(username.equals("")||password.equals("")){
            request.getRequestDispatcher("login2.html").forward(request,response);
        }else{
            for(User user:list){
                if(user.getUsername().equals(username)&&user.getPassword().equals(password)){
                    Cookie cookie1=new Cookie("username",username);
                    Cookie cookie2=new Cookie("password",password);
                    cookie1.setMaxAge(60*60);
                    cookie2.setMaxAge(60*60);
                    response.addCookie(cookie1);
                    response.addCookie(cookie2);
                    request.getRequestDispatcher("success.html").forward(request,response);
                }else{
                    request.getRequestDispatcher("login2.html").forward(request,response);
                }
            }
        }
    }
}

登錄頁面程序:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登錄</title>
</head>
<body>
<form action="./cookie4" method="Post" name="login">
    昵稱:<input name="username" type="text" placeholder="請輸入昵稱" id="nicheng"/><br/><br/>
    密碼:<input name="password" type="password" placeholder="請輸入密碼" id="mima"/><br/><br/>
    請輸入驗證碼:<br/>
    <img src="./yzm01" height="32" id="myyzm">
    <button type="button" value="看不清楚,再來一張" onclick="identifyload()">看不清楚,再來一張</button>
    <input name="yzm01" type="text"/><br/>
    <button type="submit" value="登錄" >登錄</button>
    <button type="reset" value="重置">重置</button>
</form>
</body>
</html>

User:

public class User {
    private String Username;
    private String password;

    public String getUsername() {
        return Username;
    }

    public String getPassword() {
        return password;
    }

    public void setUsername(String username) {
        Username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

UserService:

package com.westos.untitle2.CityService;

import com.westos.untitle2.bean.User;
import sun.rmi.log.LogInputStream;

import java.util.ArrayList;
import java.util.List;

public class UserService {
    public List<User> setUser(){
        List<User> list=new ArrayList<>();
        User u1=new User();
        u1.setUsername("Bighead");
        u1.setPassword("4214963");
        list.add(u1);
        User u2=new User();
        u2.setUsername("lyy");
        u2.setPassword("0829");
        list.add(u2);
        return list;
    }
}

success.html程序,自己根據需求設置.

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

朝阳区| 翁牛特旗| 黄大仙区| 文成县| 陆丰市| 黄梅县| 昆明市| 荥阳市| 宁武县| 尖扎县| 龙山县| 新河县| 商丘市| 贺兰县| 徐水县| 资中县| 托克逊县| 吴江市| 福泉市| 冀州市| 石城县| 宝兴县| 马龙县| 湄潭县| 周宁县| 通许县| 淮安市| 玛沁县| 巫山县| 昌乐县| 泸定县| 万盛区| 双流县| 乌兰察布市| 滦南县| 措美县| 郑州市| 敦化市| 临武县| 寻乌县| 乌苏市|