求助,
测试类是可以获取到数据库的数据的,但是jsp页面就是不显示,不知道是什么原因。。 servlet:
package com.xxxx.controller;
import com.xxxx.entity.User;
import com.xxxx.service.UserService;
import com.xxxx.service.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@WebServlet("/userListServlet")
public class UserController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
// 调用UserService完成查询
UserService service = new UserServiceImpl();
List<User> users = service.getUserList();
// HttpSession session = request.getSession();
// session.setAttribute("users",users);
// request.getRequestDispatcher("/list.jsp").forward(request,response);
// 将list存入request域
request.setAttribute("users",users);
// 转发到list.jsp
request.getRequestDispatcher("/list.jsp").forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<meta charset="UTF-8">
<head>
<title>Title</title>
<link href="css/bootstrap-5.1.3-dist-css/css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-3.4.1.js"></script>
<script src="js/bootstrap-5.1.3-dist-js/js/bootstrap.min.js"></script>
<style type="text/css">
td,th{
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h3 style="text-align: center">用户信息表</h3>
<table border="1" class="table table-bordered table-hover">
<tr class="success">
<th>编号</th>
<th>用户名</th>
<th>性别</th>
<th>学号</th>
<th>邮箱</th>
<th>操作</th>
</tr>
<c:forEach items="${users}" var="User" varStatus="s">
<%-- <%--%>
<%-- UserController userController = new UserController();--%>
<%-- userController.doPost(request,response);--%>
<%-- %>--%>
<tr>
<%-- <th>${s.count}</th>--%>
<th>${User.username}</th>
<th>${User.gender}</th>
<th>${User.student_id}</th>
<th>${User.mail}</th>
<th><a class="btn btn-default btn-sm" href="">修改</a>
<a class="btn btn-default btn-sm" href="">删除</a> </th>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
...全文
相关推荐
关于foreach循环中遇到的问题小结
主要介绍了关于foreach循环中遇到的问题总结,非常不错,具有参考借鉴价值,需要的朋友可以参考下
c:foreach的各种用法
<c:foreach 中各种标签属性的用法,特别是varStatus的巧用
JSTL标准标签库 <C:out>、<c:set>、<c:remove>和<c:catch>标记 <c:if>、<c:choose>、<c:when>和<c:otherwise>标记 <c:forEach>和<c:forTokens>标记
◎ JSTL的基本概念、安装与配置 ◎ JSTL的通用标记:<c:out>、<c:set>、<c:remove>和<c:catch>标记 ◎ 条件处理标记:<c:if>、<c:choose>、<c:when>和<c:otherwise>标记 ◎ 循环标记:<c:forEach>和<c:forTokens>标记
jstl标签 forEach详解
jstl forEach标签用法详解,里面介绍地非常详细,有实例说明的。
c标签-if-foreach-jar
前端el表达式应用。判断、循环


Web 开发
