老师,求解答
这是index.jsp页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>慕课网用户管理中心</title>
<link rel="stylesheet" href="lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="lib/2.2.4/jquery-1.12.4.min.js"></script>
<script src="lib/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="page-header">
<h1>慕课网后台管理系统 <small>用户数据管理中心</small></h1>
</div>
</div>
<div class="row">
<div class="jumbotron">
<h1>MyBatis基础入门课程!</h1>
<p>通过一个项目来完成基础部分的学习</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">查看更多,请上慕课网</a></p>
</div>
</div>
<div class="row">
<table class="table table-hover table-striped">
<tr>
<th>用户编号</th>
<th>登录账号</th>
<th>用户昵称</th>
<th>邮箱</th>
<th>联系方式</th>
<th>账号创建时间</th>
<th>用户状态</th>
<th>操作</th>
</tr>
<c:forEach var="user" items="${userList}">
<tr>
<td>1</td>
<td>admin</td>
<td>xiaomu</td>
<td>1270089912@qq.com</td>
<td>15129033023</td>
<td>2018-6-19</td>
<td>正常</td>
<td>
<a href="">查看</a>
<a href="">修改</a>
<a href="">删除</a>
</td>
</tr>
</c:forEach>
</table>
</div>
</div>
</body>
</html>
这是Servlet页面
package com.damu.servlet;
import java.io.IOException;
import java.util.List;
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 com.damu.dao.UsersDao;
import com.damu.entity.Users;
@WebServlet("/index")
public class UsersFindServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 8614699377847755549L;
private UsersDao userDao = new UsersDao();
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(req, resp);
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<Users> list;
try {
list = userDao.findAll();
req.setAttribute("userList", list);
req.getRequestDispatcher("index.jsp").forward(req, resp);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是UserDao.java文件
package com.damu.dao;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
import com.damu.entity.Users;
import com.damu.utils.SqlSessionFactoryUtils;
public class UsersDao {
private SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSessionFactory().openSession();
private List<Users> list;
public List<Users> findAll() {
try {
list = sqlSession.selectList("findAll");
} catch (Exception e) {
} finally {
sqlSession.close();
}
return list;
}
}
这是mybatis-config.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--用于加载外部的properties配置文件-->
<properties resource="db.properties"></properties>
<!--enviroments用于进行数据源的配置可以配置多个数据源,通过default属性制定当前项目的环境-->
<environments default="development">
<environment id="development">
<!--transactionManager用于配置事务管理,默认使用的JDBC事务管理-->
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper/userMapper.xml"/>
</mappers>
</configuration>
这是userMapper文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.damu.entity.Users">
<select id="findAll" resultType="com.damu.entity.Users">
select * from users
</select>
</mapper>
问题就是当把index.jsp页面的item=userList改为items="${userList}时页面什么也查不到
老师我自己测试了一下,是可以读到数据库的数据的。
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星