catalogue
Java+JSP system series implementation
Java+Servlet system series implementation
Java+SSM system series implementation
Java+SSH system series implementation
Java+Springboot system series implementation
1, System introduction
1. Development environment
Development tool: IDEA2018
JDK version: jdk1.0 eight
Mysql version: 8.0.13
2. Technical selection
Java+Jsp+Mysql
3. System functions
1. Log in to the system;
2. Addition, deletion, modification and query of pet information by the administrator.
4. Database files
/* Navicat Premium Data Transfer Source Server : MYSQL Source Server Type : MySQL Source Server Version : 80013 Source Host : localhost:3306 Source Schema : jsp_pet_management Target Server Type : MySQL Target Server Version : 80013 File Encoding : 65001 Date: 01/03/2022 11:05:12 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for admin -- ---------------------------- DROP TABLE IF EXISTS `admin`; CREATE TABLE `admin` ( `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of admin -- ---------------------------- INSERT INTO `admin` VALUES ('admin', 'admin'); -- ---------------------------- -- Table structure for pet -- ---------------------------- DROP TABLE IF EXISTS `pet`; CREATE TABLE `pet` ( `id` int(11) NOT NULL, `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, `age` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, `address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of pet -- ---------------------------- INSERT INTO `pet` VALUES (1001, 'Big cat', '3', 'Wuhan, Hubei'); INSERT INTO `pet` VALUES (1002, 'Cat two', '4', 'Changsha, Hunan'); INSERT INTO `pet` VALUES (1003, 'Gouda', '3', 'Changsha, Hunan'); INSERT INTO `pet` VALUES (1004, 'Dog two', '4', 'Changchun, Jilin'); SET FOREIGN_KEY_CHECKS = 1;
5. System screenshot
2, System display
1. Log in to the system
2. System home page
3. New pets
4. Modify pets
3, Partial code
AdminDaoImpl
package com.sjsq.dao.impl; import com.sjsq.dao.AdminDao; import com.sjsq.utils.DBUtil; import com.sjsq.entity.Admin; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * @author: shuijianshiqing * @date: 2022-03-01 * @description: Login system implementation */ public class AdminDaoImpl implements AdminDao { /** * Login system * @param admin * @return */ @Override public Admin login(Admin admin) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { // 1. Get database connection con = DBUtil.getConnection(); // 2. Write sql String sql = "select * from admin where username = ? and password = ?"; // 3. Precompiling ps = con.prepareStatement(sql); // 4. Set value ps.setObject(1, admin.getUsername()); ps.setObject(2, admin.getPassword()); rs = ps.executeQuery(); Admin adminLogin = null; if (rs.next()) { adminLogin = new Admin(); // Get the value from the database into the setter method of the entity class adminLogin.setUsername(rs.getString("username")); adminLogin.setPassword(rs.getString("password")); // The returned object is the complete object you queried return adminLogin; } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { // Close resources to avoid exceptions DBUtil.close(con, ps, rs); } return null; } }
PetDaoImpl
package com.sjsq.dao.impl; import com.sjsq.dao.PetDao; import com.sjsq.entity.Pet; import com.sjsq.utils.DBUtil; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; /** * @author: shuijianshiqing * @date: 2022-03-01 * @description: */ public class PetDaoImpl implements PetDao { @Override public List<Pet> selectAll(String sql, Object[] arr) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { // 1. Connect to the database con = DBUtil.getConnection(); // 2. Precompiling ps = con.prepareStatement(sql); if (arr != null) { for (int i = 0; i < arr.length; i++) { // Pass in the parameters of sql, transform upward, and query a field ps.setObject(i + 1, arr[i]); } } // 3. Execute sql rs = ps.executeQuery(); // 4. Save the queried data to the list List<Pet> list = new ArrayList<>(); while (rs.next()) { Pet pet = new Pet(); pet.setId(rs.getInt("id")); pet.setName(rs.getString("name")); pet.setAge(rs.getString("age")); pet.setAddress(rs.getString("address")); list.add(pet); } return list; } catch (Exception e) { e.printStackTrace(); } finally { // Close links to avoid excessive database connections DBUtil.close(con, ps, rs); } return null; } @Override public Pet selectPet(Integer id) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { // 1. Connect to the database con = DBUtil.getConnection(); // 2. Precompiling String sql = "select * from pet where id = ?"; ps = con.prepareStatement(sql); ps.setInt(1,id); // 3. Execute sql rs = ps.executeQuery(); while (rs.next()){ Pet pet = new Pet(); pet.setId(rs.getInt("id")); pet.setName(rs.getString("name")); pet.setAge(rs.getString("age")); pet.setAddress(rs.getString("address")); return pet; } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }finally { // Close resources to avoid exceptions DBUtil.close(con,ps,rs); } return null; } @Override public boolean addPet(Pet pet) { String sql = "insert into pet values (?,?,?,?)"; List<Object> list = new ArrayList<Object>(); list.add(pet.getId()); list.add(pet.getName()); list.add(pet.getAge()); list.add(pet.getAddress()); boolean flag = DBUtil.addUpdateDelete(sql,list.toArray()); if(flag){ return true; }else { return false; } } @Override public boolean updatePet(Pet pet) { String sql = "update pet set name=?,age=?,address=? where id=?"; List<Object> list = new ArrayList<Object>(); list.add(pet.getName()); list.add(pet.getAge()); list.add(pet.getAddress()); // Note that the id is at the end list.add(pet.getId()); boolean flag = DBUtil.addUpdateDelete(sql,list.toArray()); if(flag){ return true; }else { return false; } } @Override public boolean deletePet(Integer id) { String sql = "delete from pet where id=?"; List<Object> list = new ArrayList<Object>(); list.add(id); boolean flag = DBUtil.addUpdateDelete(sql,list.toArray()); if(flag){ return true; }else { return false; } } }
pet-add.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <!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>New pets</title> <link rel="stylesheet" type="text/css" href="css/common.css"> </head> <body> <%-- head --%> <jsp:include page="top.jsp"/> <h1>New pets</h1> <hr/> <div id="before"> <a href="javascript: window.history.go(-1)">Return to the previous level</a> </div> </br> <form action="pet-add-do.jsp" method="post" name="addForm"> <div> <tr> <label>Pet number:</label> <input type="text" name="id" id="id" placeholder="Please enter pet number"> </tr> </div> <div> <tr> <label>Pet name:</label> <input type="text" name="name" id="name" placeholder="Please enter pet name"> </tr> </div> <div> <tr> <label>Pet age:</label> <input type="text" name="age" id="age" placeholder="Please enter pet age"> </tr> </div> <div> <tr> <label>Pet address:</label> <input type="text" name="address" id="address" placeholder="Please enter pet address"> </tr> </div> <br> <div id="submit"> <tr> <button type="submit" onclick="return checkForm()">add to</button> <button type="reset">Reset</button> </tr> </div> </form> <script type="text/javascript"> function checkForm() { var id = addForm.id.value; var name = addForm.name.value; // Pet number and pet name cannot be empty if (id == "" || id == null) { alert("Please enter pet number"); addForm.id.focus(); return false; } else if (name == "" || name == null) { alert("Please enter pet name"); addForm.name.focus(); return false; } return true; } </script> <%-- bottom --%> <jsp:include page="bottom.jsp"/> </body> </html>
pet-add-do.jsp
<%@ page import="com.sjsq.entity.Pet" %> <%@ page import="com.sjsq.service.PetService" %> <%@ page import="com.sjsq.service.impl.PetServiceImpl" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>New pets</title> </head> <body> <% // Set the code for obtaining registration to UTF-8 request.setCharacterEncoding("UTF-8"); //Get teacher add For the account and password submitted on the JSP page, note that the string is passed, which needs to be converted to the corresponding type Integer id = Integer.parseInt(request.getParameter("id")); String name = request.getParameter("name"); String age = request.getParameter("age"); String address = request.getParameter("address"); // Save information to entity class Pet pet = new Pet(); pet.setId(id); pet.setName(name); pet.setAge(age); pet.setAddress(address); System.out.println("Added pet information"); System.out.println(pet); // Write data to database PetService petService = new PetServiceImpl(); boolean flag = petService.addPet(pet); if(flag){ response.sendRedirect("main.jsp"); }else{ response.sendRedirect("error.jsp"); } %> </body> </html>
pet-update.jsp
<%@ page import="com.sjsq.entity.Pet" %> <%@ page import="com.sjsq.service.PetService" %> <%@ page import="com.sjsq.service.impl.PetServiceImpl" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Modify pet</title> <link rel="stylesheet" type="text/css" href="css/common.css"> </head> <body> <%-- head --%> <jsp:include page="top.jsp"/> <h1>Modify pet</h1> <hr/> <% //Get main id of the JSP page Integer id = Integer.parseInt(request.getParameter("id")); PetService petService = new PetServiceImpl(); Pet pet = petService.selectPet(id); %> <div> <a href="javascript: window.history.go(-1)">Return to the previous level</a> </div> </br> <form action="pet-update-do.jsp" method="post" id="addForm"> <div> <%-- The staff number here cannot be modified --%> <tr> <label>Pet number:</label> <input type="text" name="id" id="id" placeholder="Please enter pet number" value="<%=pet.getId()%>" readonly="true"> </tr> </div> <div> <tr> <label>Pet name:</label> <input type="text" name="name" id="name" placeholder="Please enter pet name" value="<%=pet.getName()%>" autofocus="autofocus"> </tr> </div> <div> <tr> <label>Pet age:</label> <input type="text" name="age" id="age" placeholder="Please enter pet age" value="<%=pet.getAge()%>"> </tr> </div> <div> <tr> <label>Pet address:</label> <input type="text" name="address" id="address" placeholder="Please enter pet address" value="<%=pet.getAddress()%>"> </tr> </div> <br> <div id="submit"> <tr> <button type="submit" onclick="return checkForm()">modify</button> <button type="reset">Reset</button> </tr> </div> </form> <script type="text/javascript"> function checkForm() { var id = addForm.id.value; var name = addForm.name.value; // Pet number and pet name cannot be empty if (id == "" || id == null) { alert("Please enter pet number"); addForm.id.focus(); return false; } else if (name == "" || name == null) { alert("Please enter pet name"); addForm.name.focus(); return false; } return true; } </script> <%-- bottom --%> <jsp:include page="bottom.jsp"/> </body> </html>
pet-update-do.jsp
<%@ page import="com.sjsq.entity.Pet" %> <%@ page import="com.sjsq.service.PetService" %> <%@ page import="com.sjsq.service.impl.PetServiceImpl" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Modify pet</title> </head> <body> <% // Set the code for obtaining registration to UTF-8 request.setCharacterEncoding("UTF-8"); //Get teacher update For the account and password submitted on the JSP page, note that the string is passed, which needs to be converted to the corresponding type Integer id = Integer.parseInt(request.getParameter("id")); String name = request.getParameter("name"); String age = request.getParameter("age"); String address = request.getParameter("address"); // Save entity information to class Pet pet = new Pet(); pet.setId(id); pet.setName(name); pet.setAge(age); pet.setAddress(address); System.out.println("Modified PET information"); System.out.println(pet); // Write data to database PetService petService = new PetServiceImpl(); boolean flag = petService.updatePet(pet); if(flag){ response.sendRedirect("main.jsp"); }else{ response.sendRedirect("error.jsp"); } %> </body> </html>
4, Other
1. More systems
Java+JSP system series implementation
Implementation of student library management system with Java+JSP
Implementation of student information management system with Java+JSP
Implementation of user information management system with Java+JSP
Implementation of teacher information management system with Java+JSP
Implementation of student dormitory management system with Java+JSP
Realization of commodity information management system with Java+JSP
Java+Servlet system series implementation
Implementation of air booking system with Java+Servlet+JSP
Realization of news release system with Java+Servlet+JSP
Java+Servlet+JSP student dormitory management system
Implementation of library management system with Java+Servlet+JSP
Realization of parking lot management system with Java+Servlet+JSP
Realization of house rental management system with Java+Servlet+JSP
Implementation of student information management system with Java+Servlet+JSP
Implementation of student course selection management system with Java+Servlet+JSP
Java+Servlet+JSPl to realize student course selection check-in system
Implementation of pet clinic management system with Java+Servlet+JSP
Implementation of student achievement management System-1 with Java+Servlet+JSP
Java+Servlet+JSP to realize student achievement management System-2
Java+SSM system series implementation
J # ava+SSM+JSP to realize online examination system
Implementation of pet mall java + jsp + SSM system
Realizing supermarket management system with Java+SSM+JSP
Implementation of student achievement management system with Java+SSM+JSP
Implementation of student information management system with Java+SSM+JSP
Implementation of drug information management system with Java+SSM+JSP
Java+SSM+JSP+Maven to realize the online bookstore system
Java+SSM+JSP+Maven to realize the school educational administration management system
Java+SSH system series implementation
Implementation of online examination system with Java+SSH+JSP
Implementation of hospital online registration system with Java+SSH+JSP
Java+Springboot system series implementation
Implementation of marketing management system with Java+Springboot+H-ui+Maven
Java+Springboot+Bootstrap+Maven to realize the online mall system
Implement scenic spot tourism management system with Java+Springboot+Bootstrap+Maven
1. For more java web systems, please pay attention to the column.
2. For more JavaSwing systems, please pay attention to the column.
2. Source code download
sql is under the sql folder
Implementation of Web pet information management system with Java+JSP+Mysql
3. Operation project
Super detailed video tutorial on how to import Java Web project from IDEA
4. Remarks
If there is infringement, please contact me to delete.
5. Support bloggers
If you think this article is helpful to you, please pay attention to it. I wish you a happy life!