首页 > 其他分享 >2.14 登录页面

2.14 登录页面

时间:2024-02-28 14:12:41浏览次数:15  
标签:hhh 登录 jakarta request import 2.14 servlet response 页面

package com.example.demo;

import bean.Base_InformationBean;
import bean.InfoDAO;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(value = "/updatepwd_servlet")
public class UpdatePwdServlet extends HttpServlet {
    private String code;
    private String password;
    private Base_InformationBean hhh;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        code=request.getParameter("nameid");
        password=request.getParameter("pwd");
        hhh=new Base_InformationBean();
        hhh.setCode(code);
        hhh.setPassword(password);
        boolean flag= new InfoDAO().updateCode(hhh);
        request.setAttribute("msg","密码修改完成");
        try {
            request.getRequestDispatcher("index.jsp").forward(request,response);
            } catch (ServletException e) {
                throw new RuntimeException(e);
            }
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
        doGet(request,response);
    }
}
复制代码

登录后界面

复制代码
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div style="text-align: center">
    <h1 style="text-align: center;color: red">您已经登录成功</h1>
    <jsp:useBean id="Info" class="bean.Base_InformationBean">
        <jsp:setProperty name="Info" property="code" value="${sessionScope.User.code}"></jsp:setProperty>
        <jsp:setProperty name="Info" property="password" value="密码不能告诉你哟"></jsp:setProperty>
    </jsp:useBean>
    <p>
        <jsp:getProperty name="Info" property="code"/>
    </p>
    <p>
        <jsp:getProperty name="Info" property="password"/>
    </p>
    <a href="confirm.jsp">修改密码</a>
</div>
</body>
</html>
复制代码

修改密码的确认密码:

复制代码
<%--
  Created by IntelliJ IDEA.
  User: 龚涵彬
  Date: 2024/2/4
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1>身份验证</h1>
<div style="text-align: center">
    <label>您的账号</label><input name="id" readonly value="${sessionScope.User.code}" >
    <form id="change_pwd" action="confirm-servlet">
        <label for="pwd">请输入旧密码</label><input name="pwd" id="pwd" type="text"><br>
        <span id="msg" style="font-size: 12px;color:red">${msg}</span><br><br>
        <button type="button" id="btm">确认</button>
    </form>
    <script>
        document.getElementById("btm").addEventListener("click",function () {
            var pwd=document.getElementById("pwd").value;
            if(pwd.trim()===""||pwd.length===0)
            {
                document.getElementById("msg").innerText="密码不能为空";
                return;
            }
            document.getElementById("change_pwd").submit();
        })
    </script>
</div>
</body>
</html>
复制代码 复制代码
package com.example.demo;

import bean.Base_InformationBean;
import bean.InfoDAO;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value="/confirm-servlet")
public class ConfirmServlet extends HttpServlet {
    private String code;
    private String password;
    private Base_InformationBean hhh;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session= request.getSession();
        code=((Base_InformationBean)session.getAttribute("User")).getCode();
        System.out.println(code);
        password=request.getParameter("pwd");
        hhh=new Base_InformationBean();
        hhh.setCode(code);
        hhh.setPassword(password);
        boolean flag= new InfoDAO().Login(hhh);
        if(flag)
        {
            request.setAttribute("code",code);
            try {
                request.getRequestDispatcher("change_pwd.jsp").forward(request,response);
            } catch (ServletException e) {
                throw new RuntimeException(e);
            }
            session.removeAttribute("User");
            //手动注销
            session.invalidate();
        }
        else
        {
            request.setAttribute("msg","密码错误");
            try {
                request.getRequestDispatcher("confirm.jsp").forward(request,response);
            } catch (ServletException e) {
                throw new RuntimeException(e);
            }
        }
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
        doGet(request,response);
    }
}
复制代码

标签:hhh,登录,jakarta,request,import,2.14,servlet,response,页面
From: https://www.cnblogs.com/dmx-03/p/18040229

相关文章

  • 灵魂云 官网无法登录, 解决方法
    问题:1 在之前是可以通过浏览器搜索到灵魂云的官网然后登录上去的。2我现在两个电脑都有灵魂云的软件,但是一台电脑,突然app出现了问题。截图如下:3然后想要在这台电脑上登录到官网上 重新同步一下app,但是却发现 在firefox 上已经登录不上去了。估计对这个网......
  • 打包app端 登录页【非tabBar页面】底部会显示导航栏的解决办法
    如题,uniapp项目打包app后,登录页底部会显示导航栏的解决办法 首先直接在pages.Json中的对应页面配置中设置"navigationBarHidden":true这个方法是无效的"style":{       "navigationBarHidden":true   }但是可以通过js方式来控制页脚tabBar的隐藏与否:1、首......
  • .NET GUI 相关页面跳转方案
    1.NavigationView是UWP,及现在winui流行的主窗口导航方式。创建一个NavigationView,在里面放置Frame作为右侧主要的展示窗口。在CodeBehind中实现NavView的ItemInvoked事件。根据参数InvokedItem(每一个Item的Content名称),或者每一Item的Tag来确定跳转。(还需处理重复跳转......
  • uni-app分包优化、页面预加载、页面跳转等封装
    uni-app分包优化、页面预加载、页面跳转等封装:https://blog.csdn.net/qq_44209274/article/details/115913680?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170900569616800192290740%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=1......
  • SSH 证书登录
    SSH是服务器登录工具,一般情况下都采用密码登录或密钥登录。但是,SSH还有第三种登录方法,那就是证书登录。某些情况下,它是更合理、更安全的登录方法,本文就介绍这种登录方法。非证书登录的缺点密码登录和密钥登录,都有各自的缺点。密码登录需要输入服务器密码,这非常麻烦,也不安全,......
  • Web页面请求历程
    本文仅对Web页面请求历程进行简单的介绍,由于作者初学计算机网络,同时也没有学习图论的知识,若有不妥之处还请指出.一、准备DHCP、UDP、IP和以太网以我的笔记本为例,我的笔记本与网络连接,此时笔记本没有ip地址,所以无法进行操作先获取ip地址,笔记本的操作系统生成一个DHCP请求......
  • 【Django开发】0到1开发美多shop项目:用户登录模块开发。全md文档笔记(附代码 文档)
    本系列文章md笔记(已分享)主要讨论django商城项目相关知识。项目利用Django框架开发一套前后端不分离的商城项目(4.0版本)含代码和文档。功能包括前后端不分离,方便SEO。采用Django+Jinja2模板引擎+Vue.js实现前后端逻辑,Nginx服务器(反向代理)Nginx服务器(静态首页、商品详情页、uwsg......
  • uniapp nvue页面 map地图全屏设置
    因为nvue页面:100vh以及百分比不可用,所以1,可以获取当前屏幕高度然后赋值<map:latitude="latitude":longitude="longitude":style="'height:'+windowHeight*2+'rpx;'"></map>const{windowWidth,windowHeight,appName}=......
  • 解决uni-app 输入框,键盘弹起时页面整体上移问题
    我们每次在做UNIAPP小程序和H5遇到输入框时,总会在测试的时候点击输入框弹出软键盘把页面往上移动,仔细翻读uniapp文档的时候发现了一个属性adjust-position:Boolean类型,作用是键盘弹起时,是否自动上推页面1.发现将adjust-position属性设置为false。就可以了。前提是vue页面softin......
  • Linux:离线搭建vsftpd服务并记录新建用户登录报错问题(转载)
    1.检查本机是否安装过vsftpd#检查是否存在vsftpdrpm-qa|grepvsftpd2.下载离线安装包下载地址:http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64)3.开始安装vsftpd#安装vsftpdrpm-ivhvsftpd-3.0.2-21.el7.x86_64.rpm4.测试是否安装成功......