@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
MessageDao messageDao = new MessageDaoImpl();
try {
List<Message> allMessage = messageDao.getAllMessage();
if (null != allMessage){
System.out.println("allMessage");
}
req.setAttribute("messageList", allMessage);
req.getRequestDispatcher("messageList.jsp").forward(req,resp);
} catch (SQLException e) {
logger.info("发生SQLException异常", e);
}
}
这一句非常关键:
req.getRequestDispatcher("messageList.jsp").forward(req,resp);