11、Servlet——综合案例(Servlet+JDBC):管理员登录

news2024/11/18 0:37:53

目录

1、在MySQL中新建一个servletdatabase数据库,创建表admin

2、在web中创建登录页面login.html

3、在web中创建CSS文件夹,在CSS文件夹中创建login.css

 4、在web下新建注册页面register.html

5、在CSS文件夹中新建register.css

6、在CSS文件夹下新建table.css

7、在src下添加db.properties配置文件:数据库连接及连接池配置文件

8、创建www.admin.utils包:创建工具类DBUtils

9、创建www.admin.entity包:实体类Admin

10、创建com.admin.dao包:数据访问层接口AdminDao

11、创建com.admin.dao.impl包:数据访问层接口实现类AdminDaoImpl

12、创建com.admin.service包:业务逻辑层接口AdminService 

13、创建com.admin.service.impl包:业务逻辑层接口实现类AdminServiceImpl

14、创建com.admin.servlet包:Servlet类

(1)LoginServlet类:登录

(2)AdminShowAllServlet类:显示所有用户 

(3)RegisterServlet类:注册新用户

(4)DeleteServlet类:获取要删除用户的信息

(5)DeleteControllerServlet类:进行删除操作

(6)UpdateShowServlet类:显示要修改的个人信息

(7)UpdateServlet类:进行修改操作


实现登录功能,登录成功后显示所有管理员信息,登录失败给出“账号或密码错误,无法登录”提示信息 。

1、在MySQL中新建一个servletdatabase数据库,创建表admin

CREATE DATABASE servletdatabase;
USE servletdatabase;
CREATE TABLE IF NOT EXISTS `admin`(
`username` VARCHAR(20) PRIMARY KEY,
`password` VARCHAR(20) NOT NULL,
`phone` VARCHAR(11) UNIQUE NOT NULL,
`address` VARCHAR(10) NOT NULL
);

INSERT INTO `admin` VALUES
('张三','123456','18145772645','安徽合肥包河区'),
('李四','456789','15695688968','安徽合肥高新区');

2、在web中创建登录页面login.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" type="text/css" href="CSS/login.css">
</head>
<body>
<div>
    <form action="LoginServlet" method="post">
        <p><label>姓名:</label><input type="text" name="username"></p>
        <p><label>密码:</label><input type="password" name="password"></p>
        <p><input type="submit" value="登录"></p>
    </form>
</div>

</body>
</html>

3、在web中创建CSS文件夹,在CSS文件夹中创建login.css

*{
    margin: 0;
    padding: 0;
}
div{
    width: 400px;
    height: 100px;
    background-color: #ccc;
    margin: 30px auto;
    padding-top: 30px;
    text-align: center;
}
p{
    margin-top: 10px;
}
input{
    outline: none;
}

 4、在web下新建注册页面register.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="CSS/register.css">
</head>
<body>
<div>
  <form action="RegisterServlet" method="post">
    <p><label>姓名:</label><input type="text" name="username"></p>
    <p><label>密码:</label><input type="password" name="password"></p>
    <p><label>手机:</label><input type="text" name="phone"></p>
    <p><label>住址:</label><input type="text" name="address"></p>
    <p><input type="submit" value="注册"></p>
  </form>
</div>

</body>
</html>

5、在CSS文件夹中新建register.css

*{
    margin: 0;
    padding: 0;
}
div{
    width: 400px;
    height: 200px;
    background-color: #ccc;
    margin: 30px auto;
    padding-top: 30px;
    text-align: center;
}
p{
    margin-top: 10px;
}
input{
    outline: none;
}

6、在CSS文件夹下新建table.css

*{
    margin: 0;
    padding: 0;
}
table{
    margin: 20px auto;
    width: 500px;
    height: 100px;
    text-align: center;
}

7、在src下添加db.properties配置文件:数据库连接及连接池配置文件

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/servletdatabase
username=root
password=123456

initialSize=10

maxActive=30

maxIdle=5

maxWait=3000

8、创建www.admin.utils包:创建工具类DBUtils

package com.admin.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DBUtils {
    // 声明一个连接池对象
    private static DruidDataSource druidDataSource;

    static {
        // 实例化配置文件对象
        Properties properties = new Properties();

        try {
            // 加载配置文件内容
            InputStream is = DBUtils.class
                    .getResourceAsStream("/db.properties");
            properties.load(is);
            // 创建连接池
            druidDataSource = (DruidDataSource) DruidDataSourceFactory
                    .createDataSource(properties);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //返回一个数据源
    public static DataSource getDataSource(){
        return druidDataSource;
    }

}

9、创建www.admin.entity包:实体类Admin

package com.admin.entity;

public class Admin {
    private String username;
    private String password;
    private String phone;
    private String address;

    public Admin() {
    }

    public Admin(String username, String password, String phone, String address) {
        this.username = username;
        this.password = password;
        this.phone = phone;
        this.address = address;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

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

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Admin{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}

10、创建com.admin.dao包:数据访问层接口AdminDao

package com.admin.dao;

import com.admin.entity.Admin;

import java.util.List;

public interface AdminDao {
    //登录查询姓名和密码
    public Admin selectLogin(String username,String password);
    //查询所有
    public List<Admin> selectAll();
    //注册用户
    public int insert(Admin admin);
    //以手机号码为条件删除用户
    public int delete(String phone);
    //修改用户信息
    public int update(Admin admin);
    //以手机号码查询用户
    public Admin selectPhone(String phone);
}

11、创建com.admin.dao.impl包:数据访问层接口实现类AdminDaoImpl

package com.admin.dao.impl;

import com.admin.dao.AdminDao;
import com.admin.entity.Admin;
import com.admin.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class AdminDaoImpl implements AdminDao {
    //创建QueryRunner对象,并传递一个数据源
    QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());

    @Override
    public Admin selectLogin(String username, String password) {
        String sql = "SELECT * FROM `admin` WHERE username=? AND `password`=?;";
        Object[] args = {username,password};
        try {
            return queryRunner.query(sql,new BeanHandler<Admin>(Admin.class),args);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Admin> selectAll() {
        String sql = "select * from admin;";
        try {
            return queryRunner.query(sql,new BeanListHandler<Admin>(Admin.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int insert(Admin admin) {
        String sql = "insert into admin values(?,?,?,?)";
        Object[] args = {admin.getUsername(),admin.getPassword(),admin.getPhone(),admin.getAddress()};
        try {
            return queryRunner.update(sql,args);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int delete(String phone) {
        String sql = "delete from admin where phone=?;";
        try {
            return queryRunner.update(sql,phone);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int update(Admin admin) {
        String sql = "update admin set `username`=?,`password`=?,`address`=? where phone=?;";
        Object[] args = {admin.getUsername(),admin.getPassword(),admin.getAddress(),admin.getPhone()};
        try {
            return queryRunner.update(sql,args);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public Admin selectPhone(String phone) {
        String sql = "select * from admin where phone=?";
        try {
            return queryRunner.query(sql,new BeanHandler<Admin>(Admin.class),phone);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}

12、创建com.admin.service包:业务逻辑层接口AdminService 

package com.admin.service;

import com.admin.entity.Admin;

import java.util.List;

public interface AdminService {
    public Admin login(String username,String password);
    public List<Admin> selectAdmin();
    public int addAdmin(Admin admin);
    public int deleteAdmin(String phone);
    public int updateAdmin(Admin admin);
    public Admin selectOne(String phone);
}

13、创建com.admin.service.impl包:业务逻辑层接口实现类AdminServiceImpl

package com.admin.service.impl;

import com.admin.dao.AdminDao;
import com.admin.dao.impl.AdminDaoImpl;
import com.admin.entity.Admin;
import com.admin.service.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    AdminDao adminDao = new AdminDaoImpl();
    @Override
    public Admin login(String username, String password) {
        Admin admin = adminDao.selectLogin(username, password);
        if (admin != null){
            System.out.println("登陆成功");
            return adminDao.selectLogin(username, password);
        }else {
            System.out.println("登陆失败");
        }
        return null;
    }

    @Override
    public List<Admin> selectAdmin() {
        return adminDao.selectAll();
    }

    @Override
    public int addAdmin(Admin admin) {
        Admin admin1 = adminDao.selectPhone(admin.getPhone());
        if (admin1 != null){
            System.out.println("添加失败");
        }else {
            System.out.println("添加成功");
            return adminDao.insert(admin);
        }
        return 0;
    }

    @Override
    public int deleteAdmin(String phone) {
        Admin admin = adminDao.selectPhone(phone);
        if (admin != null){
            System.out.println("删除成功");
            return adminDao.delete(phone);
        }else {
            System.out.println("删除失败");
        }
        return 0;
    }

    @Override
    public int updateAdmin(Admin admin) {
        Admin admin1 = adminDao.selectPhone(admin.getPhone());
        if (admin1 != null){
            System.out.println("修改成功");
            return adminDao.update(admin);
        }else {
            System.out.println("修改失败");
        }
        return 0;
    }

    @Override
    public Admin selectOne(String phone) {
        Admin admin = adminDao.selectPhone(phone);
        if (admin != null){
            System.out.println("用户存在");
            return adminDao.selectPhone(phone);
        }else {
            System.out.println("无记录");
        }
        return null;
    }
}

14、创建com.admin.servlet包:Servlet类

(1)LoginServlet类:登录

package com.admin.servlet;

import com.admin.entity.Admin;
import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "LoginServlet", value = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取输出流
        PrintWriter printWriter = response.getWriter();

        //获取浏览器数据
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //输出获取到的数据
        System.out.println("username:"+username+"\npassword:"+password);

        //调用业务逻辑层login方法,传参username,password进行查询数据库
        Admin admin = adminService.login(username,password);

        //判断在数据库中是否查询到记录
        if (admin != null){
            //查询到记录在页面显示登录成功
            printWriter.println("<h2>登录成功</h2>");
        }else {
            //未查询到记录在页面显示登陆失败
            printWriter.println("<h2>登陆失败</h2>");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);

    }
}

(2)AdminShowAllServlet类:显示所有用户 

package com.admin.servlet;

import com.admin.entity.Admin;
import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;


//查询所有用户
@WebServlet(name = "AdminShowAllServlet", value = "/AdminShowAllServlet")
public class AdminShowAllServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        response.setContentType("text/html;charset=utf-8");
        //获取输出流
        PrintWriter printWriter = response.getWriter();

        //获取数据库中的全部记录
        List<Admin> adminList  = adminService.selectAdmin();

        //处理获取到的集合
        if (adminList.size() != 0){
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>所有admin</title>");
            printWriter.println("<link rel='stylesheet' type='text/css' href='CSS/table.css' />");
            printWriter.println("</head>");
            printWriter.println("<a href='/adminproject_war_exploded/register.html'>注册</a>");
            printWriter.println("<table border='1px' cellspacing='0'>");
            printWriter.println("<tr>");
            printWriter.println("<th>账号</th>");
            printWriter.println("<th>密码</th>");
            printWriter.println("<th>手机号码</th>");
            printWriter.println("<th>住址</th>");
            printWriter.println("<th>操作</th>");
            printWriter.println("</tr>");
            for (Admin admin:adminList){
                printWriter.println("<tr>");
                printWriter.println("<td>"+admin.getUsername()+"</td>");
                printWriter.println("<td>" + admin.getPassword() + "</td>");
                printWriter.println("<td>" + admin.getPhone() + "</td>");
                printWriter.println("<td>" + admin.getAddress() + "</td>");
                printWriter.println("<td><a href='/adminproject_war_exploded/UpdateShowServlet?phone="+admin.getPhone()+"'>修改</a> <a href='/adminproject_war_exploded/DeleteServlet?phone="+admin.getPhone()+"'>删除</a></td>");
                printWriter.println("</tr>");
            }
            printWriter.println("</table>");
            printWriter.println("</html>");
        }else {
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>所有admin</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>当前没有用户</h2>");
            printWriter.println("</body>");
            printWriter.println("</html>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);

    }
}

(3)RegisterServlet类:注册新用户

package com.admin.servlet;

import com.admin.entity.Admin;
import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "RegisterServlet", value = "/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //收参
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String address = request.getParameter("address");

        //在控制台输出接收的参数
        System.out.println("username:"+username+"\npassword:"+password+"\nphone:"+phone+"\naddress"+address);

        //创建Admin对象
        Admin admin = new Admin(username,password,phone,address);

        //调用业务逻辑层的addAdmin方法
        int num = adminService.addAdmin(admin);

        //声明输出流
        PrintWriter printWriter = response.getWriter();

        //处理返回的数据
        if (num == 1){
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>注册成功</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>注册成功</h2>");
            printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>返回首页</a>");
            printWriter.println("</body>");
            printWriter.println("</html>");
        }else {
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>注册失败</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>注册失败</h2>");
            printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>返回首页</a>");
            printWriter.println("</body>");
            printWriter.println("</html>");
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);

    }
}

(4)DeleteServlet类:获取要删除用户的信息

package com.admin.servlet;

import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "DeleteServlet", value = "/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        response.setContentType("text/html;charset=utf-8");
        //收参
        String phone = request.getParameter("phone");
        //声明输出流
        PrintWriter printWriter = response.getWriter();
        printWriter.println("<html>");
        printWriter.println("<head>");
        printWriter.println("<title>删除admin</title>");
        printWriter.println("</head>");
        printWriter.println("<body>");
        printWriter.println("<h2>确定要删除用户:"+phone+"吗?</h2>");
        printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>取消</a>");
        printWriter.println("<a href='/adminproject_war_exploded/DeleterControllerServlet?phone="+phone+"'>确定</a>");
        printWriter.println("</body>");
        printWriter.println("</html>");


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);

    }
}

(5)DeleteControllerServlet类:进行删除操作

package com.admin.servlet;

import com.admin.entity.Admin;
import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "DeleterControllerServlet", value = "/DeleterControllerServlet")
public class DeleterControllerServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        response.setContentType("text/html;charset=utf-8");
        //收参
        String phone = request.getParameter("phone");

        //声明输出流
        PrintWriter printWriter = response.getWriter();

        //删除数据库中的记录
        int num = adminService.deleteAdmin(phone);

        //处理返回的数据
        if (num == 1){
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>删除成功</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>删除成功</h2>");
            printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>返回首页</a>");
            printWriter.println("</body>");
            printWriter.println("</html>");
        }else {
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>删除失败</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>删除失败</h2>");
            printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>返回首页</a>");
            printWriter.println("</body>");
            printWriter.println("</html>");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);

    }
}

(6)UpdateShowServlet类:显示要修改的个人信息

package com.admin.servlet;

import com.admin.entity.Admin;
import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "UpdateShowServlet", value = "/UpdateShowServlet")
public class UpdateShowServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        response.setContentType("text/html;charset=utf-8");
        //声明输出流
        PrintWriter printWriter = response.getWriter();

        //收参
        String phone = request.getParameter("phone");

        //查询phone相关的记录
        Admin admin = adminService.selectOne(phone);

        //在页面中显示修改信息
        printWriter.println("<html>");
        printWriter.println("<head>");
        printWriter.println("<title>修改admin</title>");
        printWriter.println("</head>");
        printWriter.println("<body>");
        printWriter.println("<div><form action='UpdateServlet' method='post'><h2>信息修改</h2>");
        printWriter.println("<p><label>姓名:</label><input type='text' name='username' value='"+admin.getUsername()+"'></p>");
        printWriter.println("<p><label>密码:</label><input type='password' name='password' value='"+admin.getPassword()+"'></p>");
        //给phone设置只读属性,用户不能修改
        printWriter.println("<p><label>手机:</label><input type='text' name='phone' readonly='readonly' value='"+admin.getPhone()+"'></p>");
        printWriter.println("<p><label>住址:</label><input type='text' name='address' value='"+admin.getAddress()+"'></p>");
        printWriter.println("<p><input type='submit' value='修改'></p>");
        printWriter.println("</div></body>");
        printWriter.println("</html>");


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);

    }
}

(7)UpdateServlet类:进行修改操作

package com.admin.servlet;

import com.admin.entity.Admin;
import com.admin.service.AdminService;
import com.admin.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "UpdateServlet", value = "/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    //创建业务逻辑层AdminService对象
    AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //声明输出流
        PrintWriter printWriter = response.getWriter();

        //收参
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String address = request.getParameter("address");

        //创建Admin对象
        Admin admin = new Admin(username,password,phone,address);

        //调用业务逻辑层的updateAdmin方法
        int num = adminService.updateAdmin(admin);

        //处理返回结果
        if (num == 1){
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>修改成功</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>修改成功</h2>");
            printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>返回首页</a>");
            printWriter.println("</body>");
            printWriter.println("</html>");
        }else {
            printWriter.println("<html>");
            printWriter.println("<head>");
            printWriter.println("<title>修改失败</title>");
            printWriter.println("</head>");
            printWriter.println("<body>");
            printWriter.println("<h2>修改失败</h2>");
            printWriter.println("<a href='/adminproject_war_exploded/AdminShowAllServlet'>返回首页</a>");
            printWriter.println("</body>");
            printWriter.println("</html>");

        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);

    }
}

 

 

 

 

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

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

相关文章

文件包含漏洞

数据来源 本文仅用于信息安全的学习&#xff0c;请遵守相关法律法规&#xff0c;严禁用于非法途径。若观众因此作出任何危害网络安全的行为&#xff0c;后果自负&#xff0c;与本人无关。 01 文件包含漏洞概述 简单例子 PHP中的文件包含函数 02 文件包含漏洞类型及利用 本地文…

基于MATLAB的车牌识别系统设计

基于MATLAB的车牌识别系统设计 摘要 随着公路逐渐普及&#xff0c;我国的公路交通事业发展迅速&#xff0c;所以人工管理方式已经不能满着实际的需要&#xff0c;微电子、通信和计算机技术在交通领域的应用极大地提高了交通管理效率。汽车牌照的自动识别技术已经得到了广泛应…

弱网测试利器-Charles工具实战

一&#xff1a;弱网测试要点 二&#xff1a;利用抓包工具charles进行弱网设置&#xff0c;适用PC端和移动端&#xff08;IOS&#xff0f;Android&#xff09; 1、以charles 4.5.6版本为例&#xff0c;打开Proxy->Throttle Settings 2、打开Throttle Settings&#xff0c;界…

实战详细讲解Qt插件plugin的编写与用法

目录 1.Qt的插件是什么&#xff1f;优点是什么&#xff1f; 2.实战项目需求 3. 程序设计分析 4.Qt插件的编写 Q_DECLARE_INTERFACE&#xff08;类名&#xff0c;标识符&#xff09; Q_INTERFACES 5.插件的调用 总结感言&#xff1a; 1.Qt的插件是什么&#xff1f;优点是…

let/const相关的内容(一)

1.let/const的基本使用 在ES5中我们声明变量都是使用的var关键字(variable的缩写)&#xff0c;从ES6开始新增了两个关键字可以声明变量&#xff1a;let、const。 let和const在其他编程语言中都是有的&#xff0c;所以并不是新鲜的关键字&#xff0c;但是他们确实给JS带来了不一…

动态规划设计LeetCode 300. 最长递增子序列 354. 俄罗斯套娃信封问题

&#x1f308;&#x1f308;&#x1f604;&#x1f604; 欢迎来到茶色岛独家岛屿&#xff0c;本期将为大家揭晓LeetCode 300. 最长递增子序列 354. 俄罗斯套娃信封问题&#xff0c;做好准备了么&#xff0c;那么开始吧。 &#x1f332;&#x1f332;&#x1f434;&#x1f434…

【openGauss】把应用开发中的设置客户端字符编码往细了说

前言 早前写过两篇有关Oracle字符集的文章 【ORACLE】谈一谈Oracle数据库使用的字符集,不仅仅是乱码 【ORACLE】谈一谈NVARCHAR2、NCHAR、NCLOB等数据类型和国家字符集 基本说明了 ”数据字符编码“、”客户端字符编码“、”数据库字符编码“三者的关系&#xff0c;这些关系&a…

磨金石教育摄影技能干货分享|年味就是幸福圆满的味道

时光荏苒&#xff0c;时代变迁。以前是古街古巷&#xff0c;现在是高楼大厦。以前的老街&#xff0c;灯笼满街&#xff0c;烟火气十足。现在的城市商业街中霓虹灯可以展示出各种新年的影像。无论时代如何变迁&#xff0c;无论时光走了多远&#xff0c;我们对春节的期待从未改变…

吴恩达机器学习(二)——机器学习之监督模型之回归模型之线性回归模型

y-hat一般指的就是预测值 线性回归模型实例 构建模型 我们有一个房子的大小size&#xff0c;得到房屋价格&#xff08;price&#xff09;&#xff0c;通过这两个常数就可计算一个输入和输出的函数关系。 f w&#xff0c;b(x(i)) wx(i) b i指的是第几个训练数据 评估模型——…

【教程】browsermob-proxy 基于Java的代理服务 配合selenium使用

【教程】browsermob-proxy 基于Java的代理服务 配合selenium使用 配置依赖 <!-- 代理 配合 selenium进行抓包修改等 --><dependency><groupId>net.lightbody.bmp</groupId><artifactId>browsermob-core</artifactId><version>2.1.5&…

H3C Switch S1848G端口限速

需求&#xff1a;在交换机层面对接入用户的网络流量限速1.交换机信息2.主机限速前2.1本机IP和MAC信息依次打开控制面板\所有控制面板项\网络连接2.2限速前测速使用浏览器打开https://10000.gd.cn/测速3.主机限速后3.1查看主机所在交换机接口点击“网络”-“MAC地址”&#xff0…

【微信小程序】给你的页面加上一个填写进度表

前言在搭建一些与申请相关的微信小程序的时候&#xff0c;用户会遇到需要填写很多表单的情况&#xff0c;面对未知的表单数量&#xff0c;用户往往就会放弃填写申请表格。在此基础上作为开发者的我们常常会收到这样的一个任务——给申请页面加上一个填写进度表。这样不仅可以优…

274. H 指数

274. H 指数一、题目描述二、题目分析三、解题思路3.1 更换H指数定义3.2 二分法枚举H指数一、题目描述 二、题目分析 这道题比较绕&#xff0c;理解题目意思&#xff0c;根据题目的说法&#xff0c;所谓的H指数就是&#xff1a;总共有 h 篇论文分别被引用了至少 h 次。且其余的…

二战阿里巴巴成功上岸,准备了小半年,要个28k应该也算不上很高吧~

先说下我基本情况&#xff0c;本科不是计算机专业&#xff0c;现在是学通信&#xff0c;然后做图像处理&#xff0c;可能面试官看我不是科班出身没有问太多计算机相关的问题&#xff0c;因为第一次找工作&#xff0c;阿里的游戏专场又是最早开始的&#xff0c;就投递了&#xf…

Spring Cloud Alibaba系列三:集成Gateway实现路由管理

文章目录Spring Cloud Alibaba系列三&#xff1a;集成Gateway实现路由管理前言1、改造父项目 pom 文件2、创建 gateway 子 module3、配置yml文件Spring Cloud Alibaba系列三&#xff1a;集成Gateway实现路由管理 spring cloud alibaba 版本对照 spring cloud alibaba 有严格的…

【MPP数据库】TiDB表分区探索与实践

方案背景——为什么要进行分区&#xff1f; 一是老板通Tidb集群每天涉及50张表、2亿多条数据回流&#xff0c;合理使用Hash可以把写入压力打散到不同的TiKV&#xff1b; 二是对于大集团数据做聚合&#xff0c;利用分区裁剪原理&#xff0c;查询时可以充当前置索引&#xff0c…

1月第4周榜单丨飞瓜数据B站UP主排行榜(哔哩哔哩平台)发布!

飞瓜轻数发布2023年1月23日-1月29日飞瓜数据UP主排行榜&#xff08;B站平台&#xff09;&#xff0c;通过充电数、涨粉数、成长指数三个维度来体现UP主账号成长的情况&#xff0c;为用户提供B站号综合价值的数据参考&#xff0c;根据UP主成长情况用户能够快速找到运营能力强的B…

卫星地图——MAP(c++)

卫星地图 题目描述 一张矩形的卫星地图&#xff0c;有M行N列。行列中的0表示空地&#xff0c;1表示有建筑。有3种类型的建筑: L型: 仅在一行上占据连续的若干个格子&#xff0c;长度至少为2&#xff0c;至多为N C型&#xff1a;仅在一列上占据连续的若干个格子&#xff0c;…

春节机票销售大增!航空领域哪些业务风险要注意?

目录 航空领域常见的业务风险 2022年航空业务风险趋势分析 航空领域业务风险欺诈分析 如何防范航空业务风险 针对恶意网络爬虫 针对仿冒登录与内控风险 安全技术 春节旅游与出行数据陆续出炉。中国民航局数据显示&#xff0c;2023年1月21日至27日&#xff08;农历除夕至…

Linux - Linux系统

一、Linux系统Linux&#xff0c;全称GNU/Linux。Linux是一个开源、免费的操作系统&#xff0c;其稳定性、安全性、处理多并发能力已经得到业界的认可&#xff0c;目前大多数企业级应用甚至是集群项目都部署运行在linux操作系统之上&#xff0c;很多软件公司考虑到开发成本都首选…