IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> 《Java EE Web组件开发》实验二 -> 正文阅读

[Java知识库]《Java EE Web组件开发》实验二

[实验任务] 使用jsp页面完成注册、登录并显示

[任务介绍]

1.任务描述

????????网上购物是人们日常生活的重要事情之一。在超市中有很多日常生活的用品,如电饭煲、蒸锅、洗衣机、电冰箱等。

????????本任务要求,通过所学Servlet、JavaBean和JDBC知识读取数据库数据,以JSP页面的形式呈现数据,用于数据浏览。

备注:

?1)本任务需要编写4个JSP页面、6个Servlet文件(注册、登录、显示、验证码、修改、删除)、1个JavaBean文件、1个dao文件(用于实现增删改查功能)、1个数据库连接文件;

2)本任务所需要的类文件,需要按如下图所示结构创建;

3)用户先进行注册,注册成功跳转到登录页面,输入用户名和密码进行登录;登录成功跳转到显示页面,登录不成功则需要重新登录。

2.运行结果

?

?图1 注册页面?

?图2 登录界面

?

?图3 用户列表页面

图4 修改用户页面?

?图5 修改成功页面

?图6 数据表

[任务目标]

  1. 掌握Servlet和JSP运行原理;
  2. 掌握JavaBean、EL表达式和JSP标签库(JSTL)的使用;
  3. 熟练应用Servlet技术、JavaBean技术完成数据访问。

[实现思路]

  1. 先建立登录界面,通过调用数据库用户账号和密码,如果账号或密码正确,进入用户信息列表界面。
  2. 用户信息列表通过调用UserDao中的findALL方法,将对应数据库中的数据取出。
  3. 添加用户信息,同样调用UserDao中的insert方法,将数据插入数据库中,并跳转回用户信息界面
  4. 修改用户信息,调用UserDao中的update方法,修改数据库中的数据,并跳转回用户信息界面
  5. 删除用户信息,调用UserDao中的delete方法,删除数据库中对应的数据。

?

[实现代码以及运行效果]

最重要的当然是连接数据库啦~

注意:

String url = "jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf-8";?

这里面users是自己建的数据库哦(⊙o⊙)

如下所示为我建的数据库users,以及数据表user?

?id为自动编号!!!?

最后一定要导入jar包!!!(打圈圈的那个哦,这个jar包网上可以下载,如果MySQL版本比较高,可能得导入8.0.27的

废话不多说,直接上代码!!!?

?GetDBConnection.java?

package conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class GetDBConnection {
	private static Connection con;

	public static Connection getConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			
			String url = "jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf-8";
			String username = "root";
			String password = "root";
			con = DriverManager.getConnection(url, username, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}

	public static void release(Statement stat,Connection con){
		if(stat!=null){
			try{
				stat.close();
			}
			catch(Exception e){
				e.printStackTrace();
			}
			stat=null;
		}
		if(con!=null){
			try{
				con.close();
			}
			catch(Exception e){
				e.printStackTrace();
			}
			con=null;
		}
	}
	public static void release(ResultSet rs,Statement stat,Connection con){
		if(rs!=null){
			try{
				rs.close();
			}
			catch(Exception e){
				e.printStackTrace();
			}
			rs=null;
		}
		if(stat!=null){
			try{
				stat.close();
			}
			catch(Exception e){
				e.printStackTrace();
			}
			stat=null;
		}
		if(con!=null){
			try{
				con.close();
			}
			catch(Exception e){
				e.printStackTrace();
			}
			con=null;
		}
	}
}

?User.java?

package javabean;

public class User {
	private int id;
	private String username;
	private String password;
	private String realname;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	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 getRealname() {
		return realname;
	}
	public void setRealname(String realname) {
		this.realname = realname;
	}
}

??UserDao.java?

package javabean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import conn.GetDBConnection;
public class UserDao {
	private Connection con = null;
	PreparedStatement preStat = null;
	private ResultSet rs = null;
	
	public ArrayList<User> findAll(){
		ArrayList<User> list = new ArrayList<User>();
		String sql = "select * from user";
		con = GetDBConnection.getConnection();
		try{
			preStat = con.prepareStatement(sql);
			rs = preStat.executeQuery();
			while (rs.next()){
				User user = new User();
				user.setUsername(rs.getString(2));
				user.setPassword(rs.getString(3));
				user.setRealname(rs.getString(4));
				list.add(user);
			}
			return list;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			GetDBConnection.release(rs, preStat, con);
		}
		return null;
	}
	//查找
	public User findByName(String name){
		User user = new User();
		try{
			con = GetDBConnection.getConnection();
			String sql = "select * from user where username=?";
			preStat = con.prepareStatement(sql);
			preStat.setString(1, name);
			rs = preStat.executeQuery();
			if (rs.next()){
				user.setUsername(rs.getString(2));
				user.setPassword(rs.getString(3));
				user.setRealname(rs.getString(4));
			}
			return user;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			GetDBConnection.release(preStat, con);
		}
		return null;
	}
	//登录
	public boolean Login(String name, String pwd){
		try{
			con = GetDBConnection.getConnection();
			String sql = "select * from user where username=? and password=?";
			preStat = con.prepareStatement(sql);
			preStat.setString(1, name);
			preStat.setString(2, pwd);
			rs = preStat.executeQuery();
			if (rs.next()) return true;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			GetDBConnection.getConnection();
		}
		return false;
	}
	//插入
	public boolean insert(User user){
		try{
			con = GetDBConnection.getConnection();
			String sql = "insert into user values(null,?,?,?)";
			preStat = con.prepareStatement(sql);
			preStat.setString(1, user.getUsername());
			preStat.setString(2, user.getPassword());
			preStat.setString(3, user.getRealname());
			if (preStat.executeUpdate() == 1) return true;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			GetDBConnection.release(preStat, con);
		}
		return false;
	}
	//更新
	public boolean update(User user) {
		try{
			con = GetDBConnection.getConnection();
			String sql = "update user set password=?,realname=? where username=?";
			preStat = con.prepareStatement(sql);
			preStat.setString(1, user.getPassword());
			preStat.setString(2, user.getRealname());
			preStat.setString(3, user.getUsername());
			if (preStat.executeUpdate() == 1) return true;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			GetDBConnection.release(preStat, con);
		}
		return false;
	}
	//删除
	public boolean delete(String name){
		try{
			con = GetDBConnection.getConnection();
			String sql = "delete from user where username=?";
			preStat = con.prepareStatement(sql);
			preStat.setString(1, name);
			if (preStat.executeUpdate() == 1) return true;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			GetDBConnection.release(preStat, con);
		}
		return false;
	}
}

?LoginServlet.java?

package MyServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javabean.UserDao;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
	public LoginServlet() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");//帐号
		String password = request.getParameter("password");//密码
		if(username != null && !username.equals("")){
			UserDao userdao = new UserDao();
			boolean falg=userdao.Login(username, password);
			if(falg == false){
				request.setAttribute("msg1", "帐号或密码输入有误,登录失败!");
				RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
				dispatcher.forward(request, response);
			}else{
				//request.setAttribute("msg1", "登录成功!");
				request.getSession().setAttribute("userid",username);
				response.sendRedirect("ListUserServlet");
			}
		}
	}
	public void init() throws ServletException {
		// Put your code here
	}

}

??registerUser.java?

package MyServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javabean.User;
import javabean.UserDao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class registerUser extends HttpServlet {
	public registerUser() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.print("    This is ");
		out.print(this.getClass());
		out.println(", using the GET method");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		user.setRealname(realname);
		UserDao userDao = new UserDao();
		boolean flag = userDao.insert(user);
		if (flag){
			out.println("用户添加成功!");
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		}else {
			out.println("用户添加失败!");
		}
	}
	public void init() throws ServletException {
		// Put your code here
	}

}

??ListUserServlet.java?

package MyServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javabean.User;
import javabean.UserDao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListUserServlet extends HttpServlet {
	public ListUserServlet() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		UserDao userDao = new UserDao();
		ArrayList<User> list = userDao.findAll();
		request.setAttribute("list", list);
		request.getRequestDispatcher("/UserList.jsp").forward(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}
	public void init() throws ServletException {
		// Put your code here
	}

}

?addUserServlet.java?

package MyServlet;

import java.io.IOException;
import java.io.PrintWriter;
import javabean.User;
import javabean.UserDao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class addUserServlet extends HttpServlet {
	public addUserServlet() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.print("    This is ");
		out.print(this.getClass());
		out.println(", using the GET method");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		user.setRealname(realname);
		UserDao userDao = new UserDao();
		boolean flag = userDao.insert(user);
		if (flag){
			out.println("用户添加成功!");
			response.sendRedirect("../servlet/ListUserServlet");
		}else {
			out.println("用户添加失败!");
		}
	}
	public void init() throws ServletException {
		// Put your code here
	}

}

?delUserServlet.java?

package MyServlet;

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

import javabean.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class delUserServlet extends HttpServlet {
	public delUserServlet() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charste=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String username = request.getParameter("id");
		UserDao userDao = new UserDao();
		boolean flag = userDao.delete(username);
		if (flag){
			out.println("用户删除成功!");
			response.sendRedirect("../servlet/ListUserServlet");
		}else{
			out.println("用户删除失败!");
		}
	}
	public void init() throws ServletException {
		// Put your code here
	}

}

??updateUserServlet.java?

package MyServlet;

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

import javabean.User;
import javabean.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class updateUserServlet extends HttpServlet {
	public updateUserServlet() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String username = request.getParameter("id");
		UserDao userDao = new UserDao();
		User user = new User();
		user = userDao.findByName(username);
		request.setAttribute("user", user);
		request.getRequestDispatcher("/updateUser.jsp").forward(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		user.setRealname(realname);
		UserDao userDao = new UserDao();
		boolean flag = userDao.update(user);
		if (flag){
			out.println("用户修改成功!");
			response.sendRedirect("ListUserServlet");
		}else{
			out.println("用户修改失败!");
		}
	}
	public void init() throws ServletException {
		// Put your code here
	}

}

??jsp部分?

小剧场~

你:在登录部分为啥没有验证码????给我写出来💢

我:咱就是说,不会/(ㄒoㄒ)/~~俺也不知道杂肥事,产生的验证码是个“?

所以的所以,果断没有写验证码🤦?♀?

友友们可以自己尝试,写出来Q我一下,救救我?_?

🧡index.jsp(登录界面)?

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<style type="text/css">
		.outside
		{
			padding: 10px 10px 10px 10px;
			border: 1px solid black;
			width: 340px;
		}
		.inside
		{
			width: 100%;
			height: 100%;
			border: 1px solid black;
			margin-bottom:2px;
		}
		.operation{
			margin-left:130px;
		}
		#submit{
			margin-left:130px;
		}
		#reset{
			margin-left:20px;
		}
	</style>
</head>
<body>
	<div class="outside">
		<form action="/shiyan2/servlet/LoginServlet" method="post">
			<div class="inside">
				<div class="operation">欢迎登录</div>
			</div>
			<div class="inside">
				<table>
					<tr>
						<td class="label">用户名:</td>
						<td colspan="2"><input type="text" name="username" id="username"></td>
						<td valign="top"><br></td>
					</tr>
					<tr>
						<td class="label">密码:</td>
						<td colspan="2"><input type="password" name="password" id="password"></td>
						<td valign="top"><br></td>
					</tr>
				</table>
			</div>
			<div class="inside">
				<table>
					<tr>
						<td class="label">没有账号?<a href="/shiyan2/register.jsp">点击注册</a></td>
					</tr>
					<tr>
						<td colspan="3">
							<input type="submit" value="登录" class="button" id="submit">
						</td>
					</tr>
				</table>
			</div>
			<div>
			    <td colspan="2"><div align="center"><font size="-1" color="red"><b>${msg1}</b></font></div></td>
			</div>
		</form>
	</div>
</body>
</html>

?💛register.jsp(注册界面)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'register.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
		.outside
		{
			padding: 10px 10px 10px 10px;
			border: 1px solid black;
			width: 350px;
		}
		.inside
		{
			width: 100%;
			height: 100%;
			border: 1px solid black;
			margin-bottom:2px;
		}
		.operation{
			margin-left:130px;
		}
		#submit{
			margin-left:130px;
		}
		#reset{
			margin-left:20px;
		}
	</style>
  </head>
  <body>
    <div class="outside">
		<form action="servlet/registerUser" method="post">
			<div class="inside">
				<div class="operation">欢迎注册</div>
			</div>
			<div class="inside">
				<table>
					<tr>
						<td class="label">用户名:</td>
						<td colspan="2"><input type="text" name="username" id="username"></td>
						<td valign="top"><br></td>
					</tr>
					<tr>
						<td class="label">密码:</td>
						<td colspan="2"><input type="password" name="password" id="password"></td>
						<td valign="top"><br></td>
					</tr>
					<tr>
						<td class="label">真实姓名:</td>
						<td colspan="2"><input type="text" name="realname" id="realname"></td>
						<td valign="top"><br></td>
					</tr>
				</table>
			</div>
			<div class="inside">
				<table>
					<tr>
						<td class="label">已有账号?<a href="/shiyan2/index.jsp">点击登录</a></td>
					</tr>
					<tr>
						<td colspan="3">
							<input type="submit" value="注册" class="button" id="submit">
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
  </body>
</html>

💚UserList.jsp(显示用户信息界面)?

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'UserList.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body bgcolor="#ffffee">
  	<center>
  		<div>
  			<a href="/shiyan2/addUser.jsp">添加用户</a><br>
  			<font face="华文新魏">用户信息列表</font>
  		</div>
  		<div>
  			<table align="center" width="80%" border=1 bgcolor="#3CC4C4">
  				<tr>
  					<th>用户名</th>
  					<th>密码</th>
  					<th>真实姓名</th>
  				</tr>
  				<c:forEach var="user" items="${list }">
  					<tr>
						<td>${user.username }</td>
						<td>${user.password }</td>
						<td>${user.realname }</td>
						<td><a href='servlet/updateUserServlet?id=${user.username}'>修改</a>&nbsp;<a href='servlet/delUserServlet?id=${user.username}'>删除</a></td>
					</tr>
  				</c:forEach>
  			</table>
  		</div>
  	</center>
  </body>
</html>

后面增加、修改用户信息界面没有美化,可自行创作(●'?'●)?

?💙addUser.jsp(增加用户信息界面)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="servlet/addUserServlet" method="POST">
		<table align="center" width="800">
			<tr>
				<td align="right">用 户 名</td>
				<td >
				  <input name="username" type="text" id="txtUser" ></input>
				</td>
			</tr>
			<tr>
				<td align="right">密&nbsp;&nbsp;码</td>
				<td><input name="password" type="password" id="txtPwd" ></input></td>
			</tr>
			<tr>
				<td align="right">真实姓名</td>
				<td><input name="realname" type="text"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" name="submit" value="添加"/>
					<input  type="reset" name="reset" value="重置" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

?💜updateUser.jsp(更新用户信息界面)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="updateUserServlet" method="POST">
		<table align="center" width="800">
			<tr>
				<td align="right">用 户 名</td>
				<td >
				  <input name="username" type="text" id="txtUser" value=${user.username } ></input>
				</td>
			</tr>
			<tr>
				<td align="right">密&nbsp;&nbsp;码</td>
				<td><input name="password" type="password" id="txtPwd" ></input></td>
			</tr>
			<tr>
   				<td align="right">真实姓名</td>
        		<td><input name="realname" type="text" id="realname"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" name="submit" value="修改"/>
					<input  type="reset" name="reset" value="重置" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

?🍖登录界面🍖

🍜当用户名或密码错误时,提示“账号或密码输入有误,登录失败!”

?🍜当点击注册时,跳转到注册界面(点击登录跳转到登录界面)。

🍜当登录成功后进入用户信息显示界面。

?🍜点击“添加用户”跳转到添加界面。

?🍜点击添加按钮后回到用户信息显示界面,在界面中新增了一条记录,如下图所示:?

?🍜点击修改按钮进入修改界面。

?🍜点击修改按钮回到用户信息显示界面,此时列表中的信息已被更改。?

?🍜点击删除按钮,将对应行删除。?

?[总结或感悟]对运行结果所作的分析以及本次调试程序所取得的经验。如果程序未能通过,分析其原因。?

这部分不给康看👀

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2022-05-02 13:25:12  更:2022-05-02 13:25:51 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 2:03:18-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码