数据没出来 也没报错
运行了程序之后 页面是出来了..但是数据没有 控制台也没报错 怎么回事呀
运行了程序之后 页面是出来了..但是数据没有 控制台也没报错 怎么回事呀
2016-10-19
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/micro_message","root","yyx220");
String sql="select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE";
PreparedStatement statem= conn.prepareStatement(sql);
ResultSet rs=statem.executeQuery();
List<Message> messagelist =new ArrayList<Message>();
while(rs.next()){
//循环出的数据 先放在对象里
Message message =new Message();
messagelist.add(message);
//取出来的值 set进 对象里
message.setId(rs.getString("ID"));
message.setContent(rs.getString("CONTENT"));
message.setCommand(rs.getString("COMMAND"));
message.setDescription(rs.getString("DESCRIPTION"));
}
req.setAttribute("messagelist", messagelist);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.getRequestDispatcher("/WEB-INF/jsp/back/list.jsp").forward(req,resp);
}
JSP--------
<table class="tab2" width="100%">
<tbody>
<tr>
<th><input type="checkbox" id="all" onclick="#"/></th>
<th>序号</th>
<th>指令名称</th>
<th>描述</th>
<th>操作</th>
</tr>
<c:forEach items="${messagelist}" var="message" varStatus="status">
<tr<c:if test="${status.index%2!=0}">style='background-color:#ECF6EE;'</c:if>>
<td><input type="checkbox"/></td>
<td>${status.index+1}</td>
<td>${message.command}</td>
<td>${messsage.description}</td>
<td>
<a href="#">修改</a> <a href="#">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
举报