项目问题
1、为什么我的图书信息列表不显示出来?
2、为什么我点图书信息管理按钮也无法超链接到当前的图书信息展示页面?
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书后台管理</title>
<link rel="stylesheet" href="/css/index.css">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" href="/js/jquery-3.3.1.js"></script>
</head>
<body>
<header>
<div class="container">
<nav>
<a href="/management?method=bookList" >图书信息管理</a>
</nav>
<nav>
<a href="categoryList.html" >分类管理</a>
</nav>
</div>
</header>
<section class="banner">
<div class="container">
<div>
<h1>图书管理系统</h1>
<p>图书信息管理</p>
</div>
</div>
</section>
<section class="main">
<div class="container">
<form class="form-horizontal" action="/searchBook" method="post">
<div class="form-group" style="float: right;">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">查询</button>
</div>
</div>
<div class="form-group" style="float: right;width: 300px;">
<div class="col-sm-8">
<input name="searchContent" class="form-control" id="searchContent"
placeholder="输入要查询的分类" style="width: 250px">
</div>
</div>
</form>
</div>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>序号</th>
<th>图书编号</th>
<th>图书名称</th>
<th>分类</th>
<th>价格</th>
<th>图书封面</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${bookList}" var="bookList" varStatus="idx">
<tr id="tr1">
<td>${idx.index + 1}</td>
<td>${bookList.bookId}</td>
<td>${bookList.bookName}</td>
<td>${bookList.Category}</td>
<td><fmt:formatNumber pattern="¥0.00" value="${bookList.price}"></fmt:formatNumber></td>
<td><img src="${bookList.preview}"></td>
<td>
<a href="/updateBook?bookId=book0001">修改</a>
<a href="/deleteBook?bookId=book0001">删除</a>
</td>
<!--在循环显示数据时,此处的book0001可以用EL表达式进行替换-->
</tr>
</c:forEach>
</tbody>
</table>
</div>
</section>
<section class="page">
<div class="container">
<div id="fatie">
<a href="addBook.html"><button>新建</button></a>
</div>
</div>
</section>
<footer>
copy@慕课网
</footer>
</body>
</html>
package com.imooc.library.entity;
/**
* @author Comet
*/
public class Book {
private Integer bookId;
private String bookName;
private String bookCategory;
private Float price;
private String preview;
private String description;
public Book() {
}
public Book(Integer bookId, String bookName, String bookCategory, Float price, String preview, String description) {
this.bookId = bookId;
this.bookName = bookName;
this.bookCategory = bookCategory;
this.price = price;
this.preview = preview;
this.description = description;
}
@Override
public String toString() {
return "Book{" +
"bookId=" + bookId +
", bookName='" + bookName + '\'' +
", bookCategory='" + bookCategory + '\'' +
", price=" + price +
", preview='" + preview + '\'' +
", description='" + description + '\'' +
'}';
}
public Integer getBookId() {
return bookId;
}
public void setBookId(Integer bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getBookCategory() {
return bookCategory;
}
public void setBookCategory(String bookCategory) {
this.bookCategory = bookCategory;
}
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
public String getPreview() {
return preview;
}
public void setPreview(String preview) {
this.preview = preview;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
package com.imooc.library.controller;
import com.imooc.library.entity.Book;
import com.imooc.library.entity.User;
import com.imooc.library.service.BookServiceImp;
import com.imooc.library.service.UserServiceImpl;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
/**
* @author Comet
*/
@WebServlet("/management")
public class ManagementController extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method");
if ("bookList".equals(method)) {
this.list(request, response);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
User user = new User(username, password);
ServletContext servletContext = request.getServletContext();
List<User> userList = (List<User>) servletContext.getAttribute("userList");
UserServiceImpl userService = new UserServiceImpl();
if (userService.login(userList, user) == 1) {
request.getSession().setAttribute("user", user);
request.getRequestDispatcher("/WEB-INF/jsp/bookList.jsp").forward(request, response);
} else {
request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
}
}
private void list(HttpServletRequest request, HttpServletResponse response) {
BookServiceImp bookServiceImp = new BookServiceImp();
List<Book> list = bookServiceImp.bookList();
request.setAttribute("bookList", list);
try {
request.getRequestDispatcher("/WEB-INF/jsp/bookList.jsp").forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.imooc.library.service;
import com.imooc.library.dao.BookDao;
import com.imooc.library.entity.Book;
import java.util.List;
/**
* @author Comet
*/
public class BookServiceImp {
/**
* @return 获取图书信息列表
*/
public List bookList() {
List<Book> bookList = new BookDao().bookList();
return bookList;
}
}
package com.imooc.library.dao;
import com.imooc.library.entity.Book;
import com.imooc.library.utils.XmlDataSource;
import java.util.List;
/**
* 数据访问对象
* @author Comet
*/
public class BookDao {
public List<Book> bookList() {
List<Book> bookList = XmlDataSource.getBookData();
return bookList;
}
}
package com.imooc.library.utils;
import com.imooc.library.entity.Book;
import com.imooc.library.entity.User;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
/**
* @author Comet
*/
public class XmlDataSource {
private static List<User> usersData = new ArrayList<>();
private static List<Book> bookData = new ArrayList<>();
private static String userDataFile;
private static String bookDataFile;
static {
userDataFile = XmlDataSource.class.getResource("/user.xml").getPath();
bookDataFile = XmlDataSource.class.getResource("/book.xml").getPath();
}
/**
* 加载用户信息
*/
private static void reloadUser() {
// URLDecoder decoder = new URLDecoder();
try {
URLDecoder.decode(userDataFile, "UTF-8");
System.out.println(userDataFile);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
SAXReader reader = new SAXReader();
try {
Document document = reader.read(userDataFile);
List<Node> nodes = document.selectNodes("/root/user");
for (Node node : nodes) {
Element element = (Element) node;
String username = element.elementText("userName");
String userPassword = element.elementText("userPassword");
User user = new User(username, userPassword);
usersData.add(user);
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
/**
* 读取图书列表信息
*/
private static void reloadBook() {
try {
URLDecoder.decode(bookDataFile, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
SAXReader reader = new SAXReader();
try {
Document document = reader.read(bookDataFile);
List<Node> nodes = document.selectNodes("/root/book");
for (Node node : nodes) {
Element element = (Element) node;
String bookId = element.elementText("bookId");
String bookName = element.elementText("bookName");
String bookCategory = element.elementText("bookCategory");
String price = element.elementText("price");
String preview = element.elementText("preview");
String description = element.elementText("description");
Book book = new Book(Integer.valueOf(bookId), bookName, bookCategory, Float.valueOf(price), preview, description);
bookData.add(book);
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
static {
reloadUser();
reloadBook();
}
/**
* @return 返回用于信息list集合
*/
public static List<User> getUsersData() {
return usersData;
}
/**
* @return 返回图书list集合
*/
public static List<Book> getBookData() {
return bookData;
}
}
希望老师帮忙看一下哪里出问题了,还有就是这个问答区能上传文件吗,就是将整个工程压缩包上传来提问
28
收起
正在回答
1回答
同学你好
1、测试代码是可以显示出列表信息的,如下
另外点击图书信息管理也是可以进行跳转的
同学检查下控制台是否报错,如果没有报错,清理下浏览器缓存以及项目缓存试试
2、很抱歉问答区暂时没有这个功能,同学有疑问可以将代码进行反馈
祝学习愉快~
java工程师2020版
- 参与学习 人
- 提交作业 9401 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星