@WebServlet("/scoreUrl") public class ScoreController extends HttpServlet { private static final long serialVersionUID = 1L; public ScoreController() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // ScoreService scoreService = new ScoreService(); // StudentService studentService = new StudentService(); // User user = (User) request.getSession().getAttribute("loginUser"); // List<StudentScoreDto> scores = scoreService.getScoreListByStudentNo(user.getStudentNo()); // // Student student = studentService.getStudentByNo(user.getStudentNo()); // request.setAttribute("student", student); // request.setAttribute("scores", scores); CoursesService coursesSerice = new CoursesService(); User user = (User) request.getSession().getAttribute("loginUser"); List<Courses> courses = coursesSerice.getCourseList(); request.setAttribute("courses", courses); request.getRequestDispatcher("/WEB-INF/pages/score.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 17:28:28 浏览: 46
struts1中web.xml配置详解
这是一个Java Servlet,其中定义了一个名为ScoreController的类。该类继承了HttpServlet类,实现了doGet和doPost方法。在doGet方法中,它首先实例化了一个CoursesService对象,并通过调用getCoursesList方法获取了课程列表。然后,它从会话中获取了一个名为loginUser的对象,并将课程列表设置为request的属性。最后,它将请求转发到/WEB-INF/pages/score.jsp页面。在doPost方法中,它只是调用了doGet方法。
阅读全文