|
|
|
@ -1,66 +1,78 @@
|
|
|
|
|
package com.cn.servlet;
|
|
|
|
|
package com.cn.servlet; // 定义Servlet所在的包名
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.io.IOException; // 导入IOException,用于处理输入输出异常
|
|
|
|
|
import java.io.PrintWriter; // 导入PrintWriter,用于向客户端发送字符文本数据
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.servlet.ServletException; // 导入ServletException,用于处理Servlet运行时的异常
|
|
|
|
|
import javax.servlet.http.HttpServlet; // 导入HttpServlet,是所有HTTP servlet的父类
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest,代表客户端的请求信息
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; // 导入HttpServletResponse,代表服务器对客户端的响应信息
|
|
|
|
|
|
|
|
|
|
import com.cn.service.PrepService;
|
|
|
|
|
import com.cn.service.impl.PrepServiceImpl;
|
|
|
|
|
import com.cn.service.PrepService; // 导入PrepService接口,该接口定义了订单服务的方法
|
|
|
|
|
import com.cn.service.impl.PrepServiceImpl; // 导入PrepService接口的实现类,用于具体的订单业务操作
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @ClassName: DeletePrepServlet
|
|
|
|
|
* DeletePrepAmdinServlet类,用于处理管理员删除订单的请求。
|
|
|
|
|
* @ClassName: DeletePrepAmdinServlet 类名:DeletePrepAmdinServlet
|
|
|
|
|
* @Description: 管理员删除订单
|
|
|
|
|
* @author: ljy
|
|
|
|
|
* @date: 2019年9月28日 下午7:25:16
|
|
|
|
|
* @author: ljy Servlet的作者
|
|
|
|
|
* @date: 2019年9月28日 下午7:25:16 Servlet创建的日期和时间
|
|
|
|
|
*/
|
|
|
|
|
public class DeletePrepAmdinServlet extends HttpServlet {
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L; // 用于序列化
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see HttpServlet#HttpServlet()
|
|
|
|
|
* 默认构造函数。
|
|
|
|
|
*/
|
|
|
|
|
public DeletePrepAmdinServlet() {
|
|
|
|
|
super();
|
|
|
|
|
super(); // 调用父类的构造函数
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
|
* 处理GET请求的方法,用于执行删除订单的操作。
|
|
|
|
|
* @param request HttpServletRequest对象,包含客户端的请求信息
|
|
|
|
|
* @param response HttpServletResponse对象,包含服务器对客户端的响应信息
|
|
|
|
|
* @throws ServletException 抛出Servlet异常
|
|
|
|
|
* @throws IOException 抛出输入输出异常
|
|
|
|
|
*/
|
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
|
|
|
|
|
|
|
Integer prepId = (Integer) request.getAttribute("prepId");
|
|
|
|
|
// 从请求中获取订单ID
|
|
|
|
|
Integer prepId = Integer.valueOf(request.getParameter("prepId"));
|
|
|
|
|
|
|
|
|
|
// 创建订单服务对象
|
|
|
|
|
PrepService prepService = new PrepServiceImpl();
|
|
|
|
|
// 初始化记录数变量,用于存储删除操作的结果
|
|
|
|
|
int recordNumber = 0;
|
|
|
|
|
|
|
|
|
|
// 这是从管理员界面过来的,实现删除订单业务
|
|
|
|
|
prepId = Integer.valueOf(request.getParameter("prepId"));
|
|
|
|
|
// 调用PrepService的delete方法删除订单,并返回影响的记录数
|
|
|
|
|
recordNumber = prepService.delete(prepId);
|
|
|
|
|
|
|
|
|
|
// 获取PrintWriter对象,用于向客户端发送响应
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
if(recordNumber == 1) {
|
|
|
|
|
out.write("<script>alert('删除订单成功!');"
|
|
|
|
|
+ "window.location.href='GetAllPrepServlet'</script>");
|
|
|
|
|
// 如果订单删除成功,向客户端发送JavaScript代码,弹出提示并跳转到订单列表页面
|
|
|
|
|
out.write("<script>alert('删除订单成功!');" + "window.location.href='GetAllPrepServlet'</script>");
|
|
|
|
|
}else {
|
|
|
|
|
out.write("<script>alert('很抱歉,删除失败!');"
|
|
|
|
|
+ "window.location.href='GetAllPrepServlet'</script>");
|
|
|
|
|
// 如果订单删除失败,向客户端发送JavaScript代码,弹出提示并跳转到订单列表页面
|
|
|
|
|
out.write("<script>alert('很抱歉,删除失败!');" + "window.location.href='GetAllPrepServlet'</script>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关闭PrintWriter对象
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
|
* 处理POST请求的方法,此实现中直接调用doGet方法。
|
|
|
|
|
* @param request HttpServletRequest对象,包含客户端的请求信息
|
|
|
|
|
* @param response HttpServletResponse对象,包含服务器对客户端的响应信息
|
|
|
|
|
* @throws ServletException 抛出Servlet异常
|
|
|
|
|
* @throws IOException 抛出输入输出异常
|
|
|
|
|
*/
|
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
|
|
doGet(request, response);
|
|
|
|
|
doGet(request, response); // 直接调用doGet方法处理
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|