(index2.jsp)<body>
<div>
${not empty userList ? 'abc' : 'xxx' }
</div> <table>
<thead>
<tr>
<th>GID</th>
<th>GNAME</th>
<th>USERID</th>
<th>GPRICE</th>
<th>GTYPE</th>
<th>GNUMBER</th>
</tr>
</thead>
<tbody>
<c:forEach items="${userList}" var="u">
<tr>
<td>${u.GID}</td>
<td>${u.gname}</td>
<td>${u.UserId}</td>
<td>${u.gprice}</td>
<td>${u.gtype}</td>
<td>${u.gnumber}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
...........................................................
(homeServlet.java)public class HomeServlet extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1L; @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException { // TODO 查询动态数据
String sql = "SELECT * FROM T_GOODS";
List<Map<String, Object>> users = DBUtils.query(sql);
req.setAttribute("userList", users);
req.getRequestDispatcher("index2.jsp").forward(req, resp);
}
}.........................
..................
然后页面就成这样了求指导,谢谢噢
<div>
${not empty userList ? 'abc' : 'xxx' }
</div> <table>
<thead>
<tr>
<th>GID</th>
<th>GNAME</th>
<th>USERID</th>
<th>GPRICE</th>
<th>GTYPE</th>
<th>GNUMBER</th>
</tr>
</thead>
<tbody>
<c:forEach items="${userList}" var="u">
<tr>
<td>${u.GID}</td>
<td>${u.gname}</td>
<td>${u.UserId}</td>
<td>${u.gprice}</td>
<td>${u.gtype}</td>
<td>${u.gnumber}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
...........................................................
(homeServlet.java)public class HomeServlet extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1L; @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException { // TODO 查询动态数据
String sql = "SELECT * FROM T_GOODS";
List<Map<String, Object>> users = DBUtils.query(sql);
req.setAttribute("userList", users);
req.getRequestDispatcher("index2.jsp").forward(req, resp);
}
}.........................
..................
然后页面就成这样了求指导,谢谢噢
解决方案 »
- list如何转为json格式??
- 谁有myeclipse8.5win7(64 bit)
- 很贱的一个有关sql的问题 查询 判断是否被修改 然后再保存
- hibernate条件查询的问题
- JSP页面中两个iframe的问题!
- 如何做一个像BTchina那样,鼠标移过去就显示出数据库中的数据和图片的效果?
- 报错Exception in thread "Timer-2" java.lang.NullPointerException
- Struts中如何同时添加多条记录?
- java服务器端在NT下如何配置?
- tomcat启动时报错Unable to process web resource
- c3p0 连接池:Cannot open connection 求救!!
- mybatis-plus生成代码问题
所以userList 为空
在方法中打印下userList 的大小
List userList = (List<Map<String, Object>>)request.getAttribute("userList");
2.用双重循环取值
<c:forEach items="${userList}" var="map">
<c:forEach items="${map}" var="m">
<tr>
<td><c:out value="${m.key}" /></td>
<td><c:out value="${m.value}" /></td>
</tr>
</c:forEach>
</c:forEach>