无法显示数据列表,没有报错
package com.imooc.servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.bean.Message;
/**
* 列表页面初始化控制
* @author Administrator
*
*/
public class ListServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.getRequestDispatcher("/WEB-INF/jsp/back/list.jsp").forward(req, resp);
try {
Class.forName("com.mysql.jdbc.Driver");
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/micro_message","root","123456");
String sql = "select ID,COMMAND,DESCRIPTION,CONTENT from message";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
List<Message> messageList = new ArrayList<Message>();
while(rs.next()){
Message message = new Message();
message.setId(rs.getString("ID"));
message.setCommand(rs.getString("COMMAND"));
message.setContent(rs.getString("CONTENT"));
message.setDescription(rs.getString("DESCRIPTION"));
System.out.println(message);
messageList.add(message);
}
req.setAttribute("messageList", messageList);
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
<tbody>
<tr>
<th><input type="checkbox" id="all" onclick=""/></th>
<th>序号</th>
<th>指令名称</th>
<th>描述</th>
<th>操作</th>
</tr style="background-color:#ECF6EE;">
<c:forEach items="${messageList}" var="message" varStatus="status">
<tr>
<td><input type="checkbox" /></td>
<td>${status.index+1}</td>
<td>${message.command}</td>
<td>${message.description}</td>
<td>
<a href="#">修改</a>
<a href="#">删除</a>
</td>
</tr>
</c:forEach>
</tbody>