七天免登录(Cookie+session)+ 页面显示动画人物效果(萌娘+气泡效果)

news2025/2/28 14:24:28

一.七天免登录(Cookie+session),基于实现jsp页面

页面效果:勾选7天免登录复选框,输入用户名和密码,点击登录即可,登录后可在cookie中查看用户登录信息,以及用户过期时间

在这里插入图片描述

在这里插入图片描述

1.登录页面:

<div class="nav222">
                        <form>
                            <span class="loginSpan1" style="display: block;width: 300px;height: 30px;background: #FEF2F2;border: 1px solid red;font-size: 13px;padding: 5px"></span>
                            <input type="text" name="username" id="username" placeholder="用户名" required="required"><br>
                            <input type="password" name="password" id="password" placeholder="请输入登录密码" required="required"><br>
                            <%--<button onclick="loginUser()" id="loginUser">登录</button>--%>
                            <%--<button  id="loginUser">登录</button>--%>
                            <input type="button" id="loginUser"  style="color: #ffffff" value="登录">
                        </form>
                        <a href="register_user.jsp" style="margin-left: 20px;">免费注册</a>
                        <input type="checkbox" name="read_login" id="read_login"  style="width: 12px;height: 12px;margin-left: 140px;">7天免登录
                    </div>

2.script,登录请求

if(username.trim().length!=0 && password.trim().length!=0){
                    //7天免登录-获取复选框
                    var readLogin = $("#read_login").prop("checked");
                    $.ajax({
                        url:"LoginAndRegister/loginUser",
                        data:{
                            username:username,
                            password:password,
                            readLogin:readLogin
                        },
                        type:"post",
                        dataType:"json",
                        success:function (data) {
                            if (data == true) {
                                alert("登录成功");
                                location.href="index.jsp";
                            }else {
                                alert("登录失败");
                            }
                        }
                    })
                }

3.后端登录接口

//用户登录
    @RequestMapping(value = "/loginUser",method = RequestMethod.POST)
    @ResponseBody
    public boolean usernameAndPassword(@RequestParam(defaultValue = "") String username,
                                       @RequestParam(defaultValue = "") String password,
                                       @RequestParam String readLogin, HttpServletRequest request, HttpServletResponse response){



        password= MD5Utils.stringToMD5(password);
        password="96e79218965eb72c92a549dd5a330112";
        HttpSession session = request.getSession();
        User user=userService.selectUsernameAndPassword(username,password);
        if (user!=null){
          
            /*每次用户登录之后判断  用户账户金额 从而修改用户的等级  从而打相应的折扣*/
            Double user_money = user.getUser_money();
            if (user_money>=0.0 && user_money<100){
                user.setGrade("钻石");
            }else if (user_money>=100 && user_money<500){
                user.setGrade("星耀");
            }else if (user_money>=500){
                user.setGrade("王者");
            }
            int i = userService.updateUserGrade(user);
            
		    //设置session,在前端中根据参数获取值
            session.setAttribute("user",user);
            session.setAttribute("username",username);

            //判断用户是否勾选七天免登录,设置cookie
            if ("true".equals(readLogin)){
                Cookie cookie = new Cookie("username",username);
                cookie.setPath("/");
                //设置cookie,有效期时间
                cookie.setMaxAge(60*60*24*7);
                response.addCookie(cookie);
            }
            return true;
        }else {
            session.setAttribute("user",null);
            session.setAttribute("username","");
            //session.setAttribute("password","");
            return false;
        }
    }

我这里是使用jsp方式实现的,因此使用jsp方式,获取由后端传递的数据信息

在这里插入图片描述

4.启动程序,跳转页面时,会加载数据,同时,获取cookie中的数据,验证cookie

我这里是,使用Tomcat启动程序,启动完成后,会调用selectProductsByIndex,然后跳转到对应的页面,我这里是跳转到首页

http://localhost:8088/ccis_Web_exploded/product/selectProductsByIndex

在这里插入图片描述

在这里插入图片描述

selectProductsByIndex方法,代码实现

    //用户刚打开网页时  验证7天免登录
    @RequestMapping("/selectProductsByIndex")
    public String selectProductsByIndex(HttpServletRequest request){
        HttpSession session = request.getSession();
        if (session.getAttribute("user")==null){
            //读取cookie
            Cookie[] cookies = request.getCookies();
            if (cookies!=null){
                for (Cookie cookie : cookies) {
                	//根据创建时自定义的名称,获取cookie
               		//Cookie cookie = new Cookie("username",username);
                    if ("username".equals(cookie.getName())){
                        session.setAttribute("username",cookie.getValue());
                        session.setAttribute("subtotal",0.0);
                        User user2 = userService.findByUsername(cookie.getValue());
                        if (user2!=null){
                            session.setAttribute("user",user2);
                       
                        }
                    }
                }
            }
        }

System.out.println("\"///\\n\"+\n" +
                "\"//                      _ao0oo_                          //\\n\"+\n" +
                "\"//                     o8888888o                         //\\n\"+\n" +
                "\"//                     88* , *88                         //\\n\"+\n" +
                "\"//                     (| '_' |)                         //\\n\"+\n" +
                "\"//                     0\\\\  = /0                         //\\n\"+\n" +
                "\"//                  ——/'——‘——                        //\\n\"+\n" +
                "\"//                ,`  \\\\\\\\|    |// ‘,                    //\\n\"+\n" +
                "\"//                /  \\\\\\\\||| : |||  \\\\                   //\\n\"+\n" +
                "\"//               /   _|||| -:- |||- \\\\                   //\\n\"+\n" +
                "\"//               |    |\\\\\\\\\\\\ - /// |  |                 //\\n\"+\n" +
                "\"//               | \\\\_| ''\\\\——/'' |  |                  //\\n\"+\n" +
                "\"//               \\\\ .-\\\\_ '_'  ___/-.  /                 //\\n\"+\n" +
                "\"//              ___'. .'  /-.-\\\\`. .___                  //\\n\"+\n" +
                "\"//            .\\'\\' '<  '._\\\\_<|>_/_.` >'\\'.             //\\n\"+\n" +
                "\"//           | | : `_ \\\\ '.:\\\\ _ /' :. '/-.:||           //\\n\"+\n" +
                "\"//           \\\\ \\\\ `-.  \\\\_ __\\\\ /__ _  .-` //           //\\n\"+\n" +
                "\"//        =======`-.___`-.___\\\\____/___.-`__.=`=====     //\\n\"+\n" +
                "\"//                       '==========='                   //\\n\"+\n" +
                "\"//       ********************************************    //\\n\"+\n" +
                "\"//            佛祖保佑        永不宕机       永无bug        //\\n\"+\n" +
                "\"//                                                       //\\n\"+\n" +
                "\"///\\n\");*/");

        System.out.println("佛祖保佑不出错");
		
		//跳转到,首页
        return "index";
    }

可在浏览器页面中,删除自定义的cookie,这样7天免登录就失效了

二.页面显示动画人物效果(萌娘+气泡效果)

1.雪花效果

在这里插入图片描述

<script>
    /*样式一*/
    (function($){
        $.fn.snow = function(options){
            var $flake = $('<div id="snowbox" />').css({'position': 'absolute','z-index':'9999', 'top': '0px'}).html('&#10052;'),
                documentHeight 	= $(document).height(),
                documentWidth	= $(document).width(),
                defaults = {
                    minSize		: 10,
                    maxSize		: 20,
                    newOn		: 1000,
                    flakeColor	: "#FF7C00" /* 此处可以定义雪花颜色,若要白色可以改为#FFFFFF */
                },
                options	= $.extend({}, defaults, options);
            var interval= setInterval( function(){
                var startPositionLeft = Math.random() * documentWidth - 100,
                    startOpacity = 0.5 + Math.random(),
                    sizeFlake = options.minSize + Math.random() * options.maxSize,
                    endPositionTop = documentHeight - 200,
                    endPositionLeft = startPositionLeft - 500 + Math.random() * 500,
                    durationFall = documentHeight * 10 + Math.random() * 5000;
                $flake.clone().appendTo('body').css({
                    left: startPositionLeft,
                    opacity: startOpacity,
                    'font-size': sizeFlake,
                    color: options.flakeColor
                }).animate({
                    top: endPositionTop,
                    left: endPositionLeft,
                    opacity: 0.2
                },durationFall,'linear',function(){
                    $(this).remove()
                });
            }, options.newOn);
        };
    })(jQuery);
    $(function(){
        $.fn.snow({
            minSize: 5, /* 定义雪花最小尺寸 */
            maxSize: 50,/* 定义雪花最大尺寸 */
            newOn: 100  /* 定义密集程度,数字越小越密集 */
        });
    });
</script>

2.鼠标滑动出气泡效果

<!-- 鼠标滑动出气泡效果 -->
<script src="https://cdn.bootcss.com/sketch.js/1.1/sketch.min.js"></script>
<script>
    function Particle(x, y, radius) {
        this.init(x, y, radius);
    }

    Particle.prototype = {
        init: function (x, y, radius) {
            this.alive = true;
            this.radius = radius || 10;
            this.wander = 0.15;
            this.theta = random(TWO_PI);
            this.drag = 0.92;
            this.color = '#fff';
            this.x = x || 0.0;
            this.y = y || 0.0;
            this.vx = 0.0;
            this.vy = 0.0;
        },
        move: function () {
            this.x += this.vx;
            this.y += this.vy;
            this.vx *= this.drag;
            this.vy *= this.drag;
            this.theta += random(-0.5, 0.5) * this.wander;
            this.vx += sin(this.theta) * 0.1;
            this.vy += cos(this.theta) * 0.1;
            this.radius *= 0.96;
            this.alive = this.radius > 0.5;
        },
        draw: function (ctx) {
            ctx.beginPath();
            ctx.arc(this.x, this.y, this.radius, 0, TWO_PI);
            ctx.fillStyle = this.color;
            ctx.fill();
        }
    };
    let MAX_PARTICLES = 280;
    let COLOURS = ['#69D2E7', '#A7DBD8', '#E0E4CC', '#F38630', '#FA6900',
        '#FF4E50', '#F9D423'];
    let particles = [];
    let pool = [];
    let demo = Sketch.create({
        container: document.getElementById('fireworks')
    });
    demo.spawn = function (x, y) {
        if (particles.length >= MAX_PARTICLES)
            pool.push(particles.shift());
        particle = pool.length ? pool.pop() : new Particle();
        particle.init(x, y, random(10, 20)); //出气泡的大小在5px 到 10px之间
        particle.wander = random(0.5, 2.0);
        particle.color = random(COLOURS);
        particle.drag = random(0.9, 0.99);
        theta = random(TWO_PI);
        force = random(2, 8);
        particle.vx = sin(theta) * force;
        particle.vy = cos(theta) * force;
        particles.push(particle);
    };
    demo.update = function () {
        let i, particle;
        for (i = particles.length - 1; i >= 0; i--) {
            particle = particles[i];
            if (particle.alive)
                particle.move();
            else
                pool.push(particles.splice(i, 1)[0]);
        }
    };
    demo.draw = function () {
        demo.globalCompositeOperation = 'lighter';
        for (let i = particles.length - 1; i >= 0; i--) {
            particles[i].draw(demo);
        }
    };
    demo.mousemove = function () {
        let touch, max, i, j, n;
        for (i = 0, n = demo.touches.length; i < n; i++) {
            touch = demo.touches[i], max = random(1, 4);
            for (j = 0; j < max; j++) {
                demo.spawn(touch.x, touch.y);
            }
        }
    };
</script>

3.点击出富强民主效果

在这里插入图片描述

<script>
    /* --   Beautiful Mouse  -- */
    var a_idx = 0;
    jQuery(document).ready(function ($) {
        $("body").click(function (e) {
            var a = new Array("❤富强❤", "❤民主❤", "❤和谐❤", "❤文明❤", "❤自由❤", "❤平等❤", "❤公正❤", "❤法治❤",
                "❤爱国❤", "❤敬业❤", "❤诚信❤", "❤友善❤");
            var $i = $("<span></span>").text(a[a_idx]);
            a_idx = (a_idx + 5) % a.length;
            var x = e.pageX,
                y = e.pageY;
            $i.css({
                "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
                "top": y - 20,
                "left": x,
                "position": "absolute",
                "font-weight": "bold",
                "color": "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math
                    .random() * 255) + "," + Math.floor(Math.random() * 255) + ")"
            });
            $("body").append($i);
            $i.animate({
                    "top": y - 180,
                    "opacity": 1
                },
                3000,
                function () {
                    $i.remove();
                });
        });
    });
</script>

4.萌娘动画人物效果

在这里插入图片描述

<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
<script>
    //默认使用的萌娘
    L2Dwidget.init({ "model": { jsonPath:"https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json",
            "scale": 0 }, "display": { "position": "right", "width": 150, "height": 200,
            "hOffset": 0, "vOffset": -10 }, "mobile": { "show": true, "scale": 0.5 },
        "react": { "opacityDefault": 0.8, "opacityOnHover": 0.8 } });

</script>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/117940.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

通过heartbeat实现mysql高可用

192.168.6.128 主/heartbeat1 192.168.6.129 从/heartbeat2 192.168.6.131 漂移地址 主备基础&#xff1a;需要在128和129服务器上&#xff0c;搭建mysql主从复制 环境基础配置 128、129操作 # sed -i "s/SELINUXenforcing/SELINUXdisabled/g" /etc/selinux/…

C语言进阶-字符

C语言进阶-字符 #include <stdio.h> int main(int argc, char const *argv[]) {int ch;while ( (ch getchar()) ! EOF ) [putchar(ch);{printf("EOF\n"); }return 0; }强制程序结束 window 字符串数组

java和python调用matlab程序详细记录

Background 关于Java和Python调用matlab程序&#xff0c;网上相关文章很多&#xff0c;但质量不佳&#xff0c;有的前提条件也没介绍&#xff0c;你按照他的步骤来&#xff0c;他成功了&#xff0c;你失败了&#xff0c;很懵啊。我觉得&#xff0c;现在我们查询点什么东西费劲&…

C++11特性-多线程

多线程 线程不是越多越好&#xff0c;每个线程有有一个独立的堆栈空间1M.线程切换需要保存很多中间状态 商用程序的必须要求 并发的实现方法 多进程并发&#xff1a;进程通信&#xff08;同一电脑-文件、管道、共享内存、消息队列&#xff1b;不同电脑-socket&#xff09; 多线…

JSP课设:学生信息管理系统(附源码+调试)

JSP学生信息管理系统 &#xff08;1&#xff09;登录模块&#xff1a;本系统提供用户和管理员两种登陆方式&#xff0c;用户通过输入账号和密码&#xff0c;进行登录。 &#xff08;2&#xff09;注册模块&#xff1a;注册者输入账号和密码&#xff0c;并选择对应的权限级别&a…

交互式仪表板!Python轻松完成!⛵

&#x1f4a1; 作者&#xff1a;韩信子ShowMeAI &#x1f4d8; 数据分析实战系列&#xff1a;https://www.showmeai.tech/tutorials/40 &#x1f4d8; 本文地址&#xff1a;https://www.showmeai.tech/article-detail/410 &#x1f4e2; 声明&#xff1a;版权所有&#xff0c;转…

2022年iFLYTEKA.I.开发者大赛疫情微博情绪识别挑战赛

自然语言技术 零基础入门NLP - 新闻文本分类 基于word2vec的word相似度 疫情微博情绪识别挑战赛自然语言技术背景一、赛事任务二、使用步骤1.README2.数据下载3.模型训练及保存4.模型预测5.比赛结果背景 疫情发生对人们生活生产的方方面面产生了重要影响&#xff0c;并引发了…

写一个计算器【后缀表达式】(C++)

前言&#xff1a; 闲来无事&#xff0c; 用后缀表达式写了个计算器。。。 支持加()、减(-)、乘(*)、除(/)、乘方(^) 啥是后缀表达式&#xff1a; 波兰逻辑学家卢卡西维奇发明的表示表达式的方法 后缀式即逆波兰式&#xff0c;是波兰逻辑学家卢卡西维奇&#xff08;&#…

mysql根据父节点递归查询所有子节点,List转树形结构工具类

经常有业务需要递归查询MySQL树形结构某一节点的所有子节点&#xff0c;每次从网上扒拉找都得找半天&#xff0c;索性就自己总结一些自己遇到的比较好用的一些方法。 SQL方法一&#xff1a; SELECT* FROM(SELECTt1.*,IF( FIND_IN_SET( parent_id, parent_ids ) > 0, paren…

2022年先进封装行业研究报告

第一章 行业概况 封装为半导体产业核心一环&#xff0c;主要目的为保护芯片。半导体封装测试处于晶圆制造过程中的后段部分&#xff0c;在芯片制造完后&#xff0c;将晶圆进行封装测试&#xff0c;将通过测试的晶圆按需求及功能加工得到芯片&#xff0c;属于整个 IC 产业链中技…

Android平台GB28181设备接入端如何实时更新经纬度实现国标平台侧电子地图位置标注

技术背景 我们在做GB28181设备接入端的时候&#xff0c;其中有个功能&#xff0c;不难但非常重要&#xff1a;那就是GB28181实时位置的订阅&#xff08;mobileposition subscribe&#xff09;和上报(notify)。 特别是执法记录仪、智能安全帽、车载终端等场景下&#xff0c;现…

mysql-基础SQL语句CRUD

文章目录MySQL基础1&#xff0c;数据库相关概念1.1 数据库1.2 数据库管理系统1.3 常见的数据库管理系统1.4 SQL2&#xff0c;MySQL2.1 MySQL安装2.1.1 下载2.1.2 安装(解压)2.2 MySQL卸载2.3 MySQL配置2.3.1 添加环境变量2.3.2 新建配置文件2.3.3 初始化MySQL2.3.4 注册MySQL服…

国家涉及身份安全新规解读 | 《关键信息基础设施安全保护要求》

2022 年11 月 7 日&#xff0c;《信息安全技术关键信息基础设施安全保护要求》&#xff08;GB/T39204-2022&#xff09;国家标准发布。作为关键信息基础设施安全保护标准体系的构建基础&#xff0c;该标准将于 2023 年 5 月 1 日正式实施。 该标准提出了以关键业务为核心的整体…

软件测试内容的要点

软件测试内容的要点 20大的召开后&#xff0c;其中提出着力点坚持把发展经济的着力点放在实体经济上&#xff0c;加快建设制造强国、质量强国、航天强国、交通强国、网络强国、数字中国。 随着网络的快速发展&#xff0c;网络和数字已经呈现在大众的视野&#xff0c;软件产品…

2022-12-27 不下载Android Studio直接下载SDK、Platforms-tools、NDK

文章目录全平台支持&#xff01;&#xff01;&#xff01;1. 下载Command line tools only2. 解压command only3. 下载SDK, Platforms-tools, NDK全平台支持&#xff01;&#xff01;&#xff01; 1. 下载Command line tools only 官网链接&#xff1a;https://developer.and…

【电商】FMS财务管理系统---数据流转模块组成

继了解FMS财务管理系统定义之后&#xff0c;如何设计一个FMS系统成了新的问题&#xff0c;笔者在此介绍了FMS的业务逻辑和结构&#xff0c;希望对读者有所帮助。 在此还是要强调一下&#xff0c;虽然这里称之为“财务系统”&#xff0c;但和专业的财务软件有区别&#xff0c;只…

零售收银软件太难挑!实测市面上最受欢迎的收银软件,第一个好用

零售收银软件千千万&#xff0c;常常让商户老板挑得眼花缭乱&#xff0c;不少老板反馈&#xff0c;不知道怎么挑选收银系统软件才能不踩雷。本期小编收集了市场受欢迎度较高的五个零售收银软件&#xff0c;整理了它们各自的优势和劣势&#xff0c;供大家参考。 第一名&#xff…

Appium基础 — APP模拟手势高级操作(一)

APP模拟手势的动作都被封装在TouchAction类中&#xff0c;TouchAction是AppiumDriver的辅助类&#xff0c;主要针对手势操作&#xff0c;如滑动、按、拖动等&#xff0c;原理是将一系列的动作放在一个链条中发送到服务器&#xff0c;服务器接受到该链条后&#xff0c;解析各个动…

碳酸氢锂溶液除钙镁

锂及其盐类是国民经济和国防建设中具有重要意义的战略物资&#xff0c;也是与人们生活息息相关的能源材料。而碳酸锂作为锂盐的基础盐&#xff0c;是制取锂化合物和金属锂的原料&#xff0c;可作铝冶炼的电解浴添加剂&#xff0c;亦可用于合成橡胶、染料、半导体等方面。电池级…

当我把用Python做的课堂点名系统献给各科老师后,再也没挂过科

文章目录起因准备工作效果展示代码实战最后起因 刚上大学的表弟问我&#xff0c;大学准备好好玩玩&#xff0c;问我有没有什么不挂科的秘诀。 哎&#xff0c;这可就问对人了&#xff0c;要想不挂科&#xff0c;先把老师贿赂好&#xff0c;当然&#xff0c;咱们说的贿赂不是送…