package web.servlet.notify; import domain.Notify; import service.NotifyService; import service.impl.NotifyServiceImpl; 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; /** * 显示通知列表的Servlet */ @WebServlet("/notifyListServlet") public class NotifyListServlet extends HttpServlet { /** * 处理POST请求,获取所有通知并转发到通知列表页面。 * * @param request HTTP请求对象,包含客户端发送的数据。 * @param response HTTP响应对象,用于生成返回给客户端的响应。 * @throws ServletException 如果处理请求时发生错误。 * @throws IOException 如果输入或输出异常发生。 */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 设置请求的字符编码为UTF-8,以支持中文字符的正确处理 request.setCharacterEncoding("utf-8"); // 创建通知服务的实例,以便获取通知数据 NotifyService service = new NotifyServiceImpl(); List notifys = service.findAll(); request.setAttribute("notifys",notifys); request.getRequestDispatcher("/WEB-INF/notify/notifyList.jsp").forward(request,response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } } //package web.servlet.notify; // //import domain.Notify; //import service.NotifyService; //import service.impl.NotifyServiceImpl; // //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; ///** // * 显示通知列表的Servlet // */ //@WebServlet("/notifyListServlet") //public class NotifyListServlet extends HttpServlet { // /** // * 处理POST请求,获取所有通知并转发到通知列表页面。 // * // * @param request HTTP请求对象,包含客户端发送的数据。 // * @param response HTTP响应对象,用于生成返回给客户端的响应。 // * @throws ServletException 如果处理请求时发生错误。 // * @throws IOException 如果输入或输出异常发生。 // */ // protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // // 设置请求的字符编码为UTF-8,以支持中文字符的正确处理 // request.setCharacterEncoding("utf-8"); // // 创建通知服务的实例,以便获取通知数据 // NotifyService service = new NotifyServiceImpl(); // List notifys = service.findAll(); // request.setAttribute("notifys",notifys); // request.getRequestDispatcher("/WEB-INF/notify/notifyList.jsp").forward(request,response); // } // protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // doPost(request,response); // } //}