当前位置: 首页 > 工具软件 > MessageList > 使用案例 >

servlet查询所有消息"List<Message>",并跳转到页面"messageList.jsp"进行显示

裴俊雅
2023-12-01
@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);

 类似资料: