qq_纵横_11
2018-07-25 16:29
<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>${message.description}</td>
<td>
<a href="#">修改</a>
<a href="#">删除</a>
</td>
</tr>
</c:forEach>
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;
/*
* 列表页面初始化控制
*/
@SuppressWarnings("serial")
public class ListServlet extends HttpServlet{
@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");
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/micro_message","root","123456789");
String sql="select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE";
PreparedStatement statement=conn.prepareStatement(sql);
ResultSet rs=statement.executeQuery();
List<Message>messageList=new ArrayList<Message>();
while(rs.next()){
Message message=new Message();
messageList.add(message);
message.setId(rs.getString("ID"));
message.setCommand(rs.getString("COMMAND"));
message.setDescription(rs.getString("DESCRIPTION"));
message.setContent(rs.getString("CONTENT"));
}
req.setAttribute("messageList", messageList);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
已经自己解决了,是页面跳转放到了前面,导致servlet链接数据库得到的值没有成功的传进来
我后台有试着把得到的数据直接输出到控制台,是可以的,浏览器访问的时候还是出不来数据
这样看不好看出来,后台跟一下断点,前台console.log与eval结合着用一下
检查下你的数据库的几个编码格式,再看看你的页面编码格式
通过自动回复机器人学Mybatis---基础版
107412 学习 · 786 问题
相似问题
回答 2
回答 4
回答 3
回答 1
回答 3