为什么我写的和老师的代码一样,页面却不显示数据呢,

来源:3-4 列表显示页面跳转的代码实现

qq_慕UI0173712

2019-08-16 13:40:22

http://img.mukewang.com/climg/5d56413400010f4519020779.jpg

这是category_list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html>
<html>


<!-- Mirrored from admindesigns.com/demos/absolute/1.1/admin_forms-validation.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 06 Aug 2015 02:56:15 GMT -->
<head>
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">

<title> 商城--分类列表 </title>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/skin/default_skin/css/theme.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/css/admin-forms.css">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/assets/img/favicon.ico">
</head>

<body class="admin-validation-page" data-spy="scroll" data-target="#nav-spy" data-offset="200">
<div id="main">
  <%@ include file="header.jsp" %>
    
  <%@ include file="left.jsp" %>
  
    <section id="content_wrapper">
<section id="content" class="table-layout animated fadeIn">
    <div class="tray tray-center">
        <div class="content-header">
            <h2> 分类列表 </h2>
            <p class="lead"></p>
        </div>
        <div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;">
            <div class="panel  heading-border">
                <div class="panel-menu">
                    <div class="row">
                        <div class="hidden-xs hidden-sm col-md-3">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default light">
                                    <i class="fa fa-refresh"></i>
                                </button>
                                <button type="button" class="btn btn-default light">
                                    <i class="fa fa-trash"></i>
                                </button>
                                <button type="button" class="btn btn-default light">
                                    <i class="fa fa-plus" onclick="javascript:window.location.href='/employee/to_add';"></i>
                                </button>
                            </div>
                        </div>
                        <div class="col-xs-12 col-md-9 text-right">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default light">
                                    <i class="fa fa-chevron-left"></i>
                                </button>
                                <button type="button" class="btn btn-default light">
                                    <i class="fa fa-chevron-right"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel-body pn">
                    <table id="message-table" class="table admin-form theme-warning tc-checkbox-1">
                        <thead>
                        <tr class="">
                            
                            <th class="hidden-xs">名称</th>
                          
                            <th class="hidden-xs">描述</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        	<c:forEach var=" category "  items="${list }">
                            <tr class="message-unread">
                                <td>${category.cname }</td>
                                <td>${category.cdesc}</td>
                                <td>
                                    <a href="#">编辑</a>
                                    <a href="#">删除</a>
                                </td>
                            </tr>
                                 	</c:forEach>
                        	
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

</section>
</div>
<style>
    /* demo page styles */
    body { min-height: 2300px; }

    .content-header b,
    .admin-form .panel.heading-border:before,
    .admin-form .panel .heading-border:before {
        transition: all 0.7s ease;
    }
    /* responsive demo styles */
    @media (max-width: 800px) {
        .admin-form .panel-body { padding: 18px 12px; }
    }
</style>

<style>
    .ui-datepicker select.ui-datepicker-month,
    .ui-datepicker select.ui-datepicker-year {
        width: 48%;
        margin-top: 0;
        margin-bottom: 0;

        line-height: 25px;
        text-indent: 3px;

        color: #888;
        border-color: #DDD;
        background-color: #FDFDFD;

        -webkit-appearance: none; /*Optionally disable dropdown arrow*/
    }
</style>
<script src=" ${pageContext.request.contextPath } /vendor/jquery/jquery-1.11.1.min.js"></script>
<script src=" ${pageContext.request.contextPath } /vendor/jquery/jquery_ui/jquery-ui.min.js"></script>
<script src=" ${pageContext.request.contextPath }/ assets/admin-tools/admin-forms/js/jquery.validate.min.js"></script>
<script src=" ${pageContext.request.contextPath } /assets/admin-tools/admin-forms/js/additional-methods.min.js"></script>
<script src=" ${pageContext.request.contextPath } /assets/admin-tools/admin-forms/js/jquery-ui-datepicker.min.js"></script>
<script src=" ${pageContext.request.contextPath }/ assets/js/utility/utility.js"></script>
<script src=" ${pageContext.request.contextPath } /assets/js/demo/demo.js"></script>
<script src=" ${pageContext.request.contextPath }/ assets/js/main.js"></script>
<script type="text/javascript" src=" ${pageContext.request.contextPath } /js/pages.js"></script>
<script type="text/javascript" src=" ${pageContext.request.contextPath } /js/items.js"></script>
</body>
</html>

这是CategoryDaoImpl.java

package com.winking.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.winking.dao.CategoryDao;
import com.winking.domain.Category;
import com.winking.utils.JDBCUtils;

public class CategoryDaoImpl implements CategoryDao {

	@Override
	public List<Category> findAll() {
System.out.println("CategoryDao的findAll方法执行了...");
Connection conn =null;
PreparedStatement pstmt=null;
ResultSet rs=null;
List<Category> list = null;
try {
	//1.获得连接
	conn=JDBCUtils.getConnection();
	//2.编写SQL
	String sql ="select * from category";
	//3.预编译SQL
	pstmt= conn.prepareStatement(sql);
	//4.设置参数
	//5.执行SQL
	rs=pstmt.executeQuery();
	//6.结果处理
	list= new ArrayList<Category>();
	while(rs.next()) {
		Category category= new Category();
		category.setCid(rs.getInt("cid"));
		category.setCname(rs.getString("cname"));
		category.setCdesc(rs.getString("cdes"));
		
		list.add(category);
	}

}catch(Exception e) {
	e.printStackTrace();
}finally {
	//7.释放资源
	JDBCUtils.release(rs, pstmt,conn);
}
return list;
	}

}


写回答

3回答

好帮手慕柯南

2019-08-16

同学你好!

同学这里var后面的空格也会被定义为这个变量的名字里面,这样变量的名字就是:

空格+category+空格。所以通过category就获取不到值了,同学将前后的空格去掉就可以了

http://img.mukewang.com/climg/5d567e910001b2ac04480170.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

0

qq_慕UI0173712

提问者

2019-08-16

http://img.mukewang.com/climg/5d56740400017e8b07210212.jpg

0

好帮手慕柯南

2019-08-16

同学你好!

  1. 数据库中有数据吗?

  2. 是否将查询到的数据返回页面

    http://img.mukewang.com/climg/5d565c660001131309580357.jpg

  3. idea或者浏览器的控制台是否报错。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

0
hq_慕UI0173712
h 有显示~~详细如上图
h019-08-16
共1条回复

0 学习 · 8016 问题

查看课程