当前位置:网站首页>Online bookstore system based on jsp+servlet+mysql
Online bookstore system based on jsp+servlet+mysql
2022-07-25 08:07:00 【two billion sixteen million eight hundred and fifty-five thousa】
The login page

User registration

Books add

Book information management

Add book pictures

User information management

Technical description
development tool : Idea/Eclipse
database : mysql
Jar Warehouse : Jar package
Front frame :jquery/Jsp
Back end framework : Jsp/Servlet
package com.tenton.servlet;
import com.tenton.pojo.Book;
import com.tenton.service.BookService;
import com.tenton.service.Impl.BookServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
/**
* @Date: 2021/1/19
* @Author: Tenton
* @Description: According to the user Id Delete user
*/
@WebServlet(name = "AddBookServlet",urlPatterns = "/addBookServlet")
public class AddBookServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the encoding format , Prevent confusion code
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
BookService bookService = new BookServiceImpl();
// The book Id
String bookId = request.getParameter("id");
int id = 0;
// Determine whether it is null , Then it is transformed into int type
if(bookId !=null && !bookId.equals("")){
id = Integer.parseInt(bookId);
}
// The name of the book
String bookName = request.getParameter("bookName");
// author
String author = request.getParameter("author");
// Press.
String press = request.getParameter("press");
// Book unit price
String bookPrice = request.getParameter("price");
BigDecimal price = new BigDecimal(bookPrice);
// Number
int num = Integer.parseInt(request.getParameter("num"));
// Book illustrations route
String image = request.getParameter("image");
if (id > 0) {
// Create a Book Entity , Save the value passed from the front end
Book book = new Book(id, bookName, author, press, price, num, image);
int result = bookService.insertBook(book);
// Judge whether the addition is successful
if (result > 0) {
response.getWriter().print("<script>alert(' Add success !')</script>");
response.sendRedirect("/listBookServlet");
} else {
response.getWriter().write(" Add failure ,2 Seconds later, it will automatically jump to the main interface ");
response.setHeader("Refresh", "3;URL=/listBookServlet");
}
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
}
package com.tenton.servlet;
import com.tenton.pojo.User;
import com.tenton.service.Impl.UserServiceImpl;
import com.tenton.service.UserService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @Date: 2021/1/19
* @Author: Tenton
* @Description: Query all users
*/
@WebServlet(name = "ListUserServlet",urlPatterns = "/listUserServlet")
public class ListUserServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the encoding format , Prevent confusion code
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
UserService userService = new UserServiceImpl();
// Get all user information
List<User> users = userService.listUser();
// Store the obtained user information in the linked list request domain , Pass it on to the front end
request.setAttribute("users",users);
// Request forwarding to userManager page
request.getRequestDispatcher("/userManager.jsp").forward(request,response);
}
}
边栏推荐
- Raspberry pie 3b ffmpeg RTMP streaming
- Raspberry pie 4B ffmpeg RTMP streaming
- yolov7 网络架构深度解析
- 对无法重新创建的表进行了更改或者启用了“阻止保存要求重新创建表的更改”选项
- Can Flink's current capabilities support the synchronization of a table from source (MySQL) to sink (MySQL) to separate databases and tables
- 第3章业务功能开发(查询线索)
- While (~scanf ("%d", & n)) is equivalent to while (scanf ("%d", & n)! =eof)
- 刷题《剑指Offer》day02
- 文件详细操作
- How to obtain the intersection / subtraction / Union of two sets by MySQL
猜你喜欢

Redis分片集群

交叉熵计算公式
Cache design in Web services (error allowed, error not allowed)

Svg creative underline style JS special effect

如何仅用递归函数和栈操作逆序一个栈

How does MTK change the boot logo?

Science: listening to music can really relieve pain. Chinese scientists reveal the neural mechanism behind it

Native form submission data

ArcGIS Pro脚本工具(10)——从图层生成.stylx样式符号

Niuke dynamic planning training
随机推荐
UNIPRO multi terminal deployment to meet customers' diversified needs
Enq: HW - fault analysis caused by content waiting
滴滴 - eta(Estimate the Travel Time)
Today in history: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
Weblux default IO threads
If Debian infringes the rust trademark, will it be exempted by compromising and renaming?
How should enterprise users choose aiops or APM?
Leetcode (Sword finger offer) - 04. search in two-dimensional array
Programmers can't play at the age of 35. Is it a fact or a misunderstanding?
[recommended reading] a collection of super useful vulnerability scanning tools!
uiautomator2 常用命令
Changes were made to tables that cannot be recreated or the prevent saving changes that require the table to be recreated option was enabled
CSDN custom T-shirts are waiting for you to get, and the benefits of new programmer are coming!
第十七届振兴杯计算机程序设计员(云计算平台运维与开发)决赛
交叉熵计算公式
P1086 [NOIP2004 普及组第二题] 花生采摘
Common commands of raspberry pie
Learn when playing No 6 | the magic of document library lies in
File details
2022-07-19 Daily: too many icml2022 papers to read? "One sentence comments on 1234 paper highlights" helps you quickly lock