package controller;
import Service.AddProduct;
import Service.GetCart;
import bean.user;
import dao.select;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "controller.AddCarServlet", urlPatterns = "/controller.AddCarServlet")
public class AddCarServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("product_name");
String email = request.getParameter("email");
user user = new select().getUser(email);
int count = Integer.parseInt(request.getParameter("count"));
response.setContentType("text/html;charset=GBK");
PrintWriter printWriter = response.getWriter();
if(email == null)
{
printWriter.println("<script>alert(\"您需要先登录\");</script>");
printWriter.println("<script>window.location.href='product.jsp'</script>");
}
else
{
new AddProduct().addProduct(email,product_name,count);
user.setShoppingCart(new GetCart().getCart(user));
request.getSession().setAttribute("user",user);
printWriter.println("<script>window.location.href='product.jsp'</script>");
}
}
}
package controller;
import Service.AddProduct;
import Service.GetCart;
import bean.user;
import dao.select;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "controller.AddCarServlet", urlPatterns = "/controller.AddCarServlet")
public class AddCarServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("product_name");
String email = request.getParameter("email");
user user = new select().getUser(email);
int count = Integer.parseInt(request.getParameter("count"));
response.setContentType("text/html;charset=GBK");
PrintWriter printWriter = response.getWriter();
if(email == null)
{
printWriter.println("<script>alert(\"您需要先登录\");</script>");
printWriter.println("<script>window.location.href='product.jsp'</script>");
}
else
{
new AddProduct().addProduct(email,product_name,count);
user.setShoppingCart(new GetCart().getCart(user));
request.getSession().setAttribute("user",user);
printWriter.println("<script>window.location.href='product.jsp'</script>");
}
}
}
package controller;
import dao.insert;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import bean.product;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "controller.AddProductServlet", urlPatterns = "/controller.AddProductServlet")
public class AddProductServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("product_name");
String brand_name = request.getParameter("brand_name");
PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=GBK");
int amount = Integer.parseInt(request.getParameter("amount"));
double price = Double.parseDouble(request.getParameter("price"));
String description = request.getParameter("type_name");
String type_name = request.getParameter("type_name");
product product = new product(product_name,brand_name,amount,price,description,type_name,null);
System.out.println(product.toString());
int count = new insert().AddProduct(product);
if(count == 1)
{
out.println("<script>alert(\"添加成功\");</script>");
out.println("<script>window.location.href='http://localhost:8080/html/ProductNew.jsp'</script>");
}
else
{
out.println("<script>alert(\"添加失败\");</script>");
out.println("<script>window.location.href='http://localhost:8080/html/ProductNew.jsp'</script>");
}
}
}
package controller;
import dao.insert;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import bean.product;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "controller.AddProductServlet", urlPatterns = "/controller.AddProductServlet")
public class AddProductServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("product_name");
String brand_name = request.getParameter("brand_name");
PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=GBK");
int amount = Integer.parseInt(request.getParameter("amount"));
double price = Double.parseDouble(request.getParameter("price"));
String description = request.getParameter("type_name");
String type_name = request.getParameter("type_name");
product product = new product(product_name,brand_name,amount,price,description,type_name,null);
System.out.println(product.toString());
int count = new insert().AddProduct(product);
if(count == 1)
{
out.println("<script>alert(\"添加成功\");</script>");
out.println("<script>window.location.href='http://localhost:8080/html/ProductNew.jsp'</script>");
}
else
{
out.println("<script>alert(\"添加失败\");</script>");
out.println("<script>window.location.href='http://localhost:8080/html/ProductNew.jsp'</script>");
}
}
}
package controller;
import dao.Update;
import dao.insert;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "controller.ADDServlet", urlPatterns = "/controller.ADDServlet")
public class ADDServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("product_name");
int NewAmount = Integer.parseInt(request.getParameter("NewAmount"));
response.setContentType("text/html;charset=GBK");
PrintWriter printWriter = response.getWriter();
int result = new Update().AddNUM(NewAmount,product_name);
if(result == 1)
{
printWriter.println("<script>alert(\"添加成功\");</script>");
printWriter.println("<script>window.location.href='http://localhost:8080/html/ProductAdd.jsp'</script>");
}
else
{
printWriter.println("<script>alert(\"添加失败\");</script>");
printWriter.println("<script>window.location.href='http://localhost:8080/html/ProductAdd.jsp'</script>");
}
}
}
package controller;
import dao.Update;
import dao.insert;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "controller.ADDServlet", urlPatterns = "/controller.ADDServlet")
public class ADDServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("product_name");
int NewAmount = Integer.parseInt(request.getParameter("NewAmount"));
response.setContentType("text/html;charset=GBK");
PrintWriter printWriter = response.getWriter();
int result = new Update().AddNUM(NewAmount,product_name);
if(result == 1)
{
printWriter.println("<script>alert(\"添加成功\");</script>");
printWriter.println("<script>window.location.href='http://localhost:8080/html/ProductAdd.jsp'</script>");
}
else
{
printWriter.println("<script>alert(\"添加失败\");</script>");
printWriter.println("<script>window.location.href='http://localhost:8080/html/ProductAdd.jsp'</script>");
}
}
}