<span style="font-family:FangSong_GB2312;font-size:18px;">import java.text.*; import java.util.*; import java.io.*; import javax.servlet.http.*; import javax.servlet.*; import com.bjpowernode.exam.model.*; import com.bjpowernode.exam.manager.*; public class SearchStudentServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String sBeginDate = request.getParameter("beginDate"); String sEndDate = request.getParameter("endDate"); Date beginDate = new Date(); Date endDate = new Date(); try { beginDate = new SimpleDateFormat("yyyy-MM-dd").parse(sBeginDate); endDate = new SimpleDateFormat("yyyy-MM-dd").parse(sEndDate); }catch(Exception e) { e.printStackTrace(); } StudentManager studentManager = new StudentManagerImpl(); List<Student> studentList = studentManager.findStudentList(beginDate, endDate); //将学生列表设置到requet范围中 //request.setAttribute("student_list", studentList); //转发,转发是在服务器端转发的,客户端是不知道的 //request.getRequestDispatcher("/student_list.jsp").forward(request, response); //将studentList放到session中 HttpSession session = request.getSession(); session.setAttribute("student_list", studentList); //重定向,不会共享request //以下写法错误,该 "/"代表了8080端口 //response.sendRedirect("/student_list.jsp"); response.sendRedirect(request.getContextPath() + "/student_list.jsp"); } }</span> |