每日随笔

今天尝试简化代码,将HttpSession session = req.getSession();放到最前面,但是由于servlet中要求的req都是在形参中事先定义好的,只能在每个函数中具体定义具体实现,而且在加入session之后还需要进行throw抛出异常。

private void select(HttpServletRequest req, HttpServletResponse resp, String name) throws Exception, IOException {
req.setCharacterEncoding("utf-8");
teacher tea = dao.Select(name);
HttpSession session = req.getSession();
session.setAttribute("tea", tea);
req.getRequestDispatcher("sightteacher.jsp").forward(req, resp);
return;
}

原文地址:https://www.cnblogs.com/buxiang-Christina/p/14159243.html