求助,

游泳的考拉 游泳的考拉 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

测试类是可以获取到数据库的数据的,但是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>&nbsp;
                    <a class="btn btn-default btn-sm" href="">删除</a> </th>
                </tr>
            </c:forEach>
        </table>
    </div>
</body>
</html>

 

...全文
评论 2
收藏 已收藏
分享
返回顶部
游泳的考拉
Web 开发 81,108 成员 341,721 内容