为了账号安全,请及时绑定邮箱和手机立即绑定

无法显示数据列表,没有报错

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>&nbsp;&nbsp;&nbsp;

<a href="#">删除</a>

</td>

</tr>

</c:forEach>

</tbody>


正在回答

1 回答

应该把req.getRequestDispatcher("/WEB-INF/jsp/back/list.jsp").forward(req, resp); 放在方法最后。

代码是从上到下依次执行的

1 回复 有任何疑惑可以回复我~
#1

哎呀呀125

解决了我的问题,非常感谢!
2017-01-19 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

无法显示数据列表,没有报错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信