@WebServlet("/buycoursesUrl") public class BuyCoursesController extends HttpServlet { private static final long serialVersionUID = 1L; public BuyCoursesController() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { CoursesService coursesSerice = new CoursesService(); User user = (User) request.getSession().getAttribute("loginUser"); List<StudentBuy> StudentBuy = coursesSerice.getBuyCourseList(user.getUsername()); request.setAttribute("buys", StudentBuy); request.getRequestDispatcher("/WEB-INF/pages/buycourses.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
时间: 2024-04-07 13:28:45 浏览: 43
注解——WebSerlvet1
这是一个基于 Java Servlet 技术实现的课程信息管理系统中的购买课程的控制器类。它接收一个 HTTP GET 请求,从当前用户的会话中获取登录的用户对象,并调用 CoursesService 类的 getBuyCourseList 方法获取该用户已购买的课程列表。然后将获取到的课程列表存储到 request 对象的属性中,并转发到购买课程页面进行显示。如果接收到的是 HTTP POST 请求,则会调用 doGet 方法进行处理。
阅读全文