老师,我的修改怎么不成功啊?
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改图书信息</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/add.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/dept/list.do">
图书信息管理
</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, XXX!</h1>
<p>请小心的修改图书信息。。。</p>
</div>
<div class="page-header">
<h3><small>修改</small></h3>
</div>
<form class="form-horizontal" action="${pageContext.request.contextPath }/AddBookServlet" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">图书编号 :</label>
<div class="col-sm-8">
<input name="bookId" class="form-control" id="bookId" readonly="readonly">
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">图书名称 :</label>
<div class="col-sm-8">
<input name="bookName" class="form-control" id="bookName">
</div>
</div>
<div class="form-group">
<label for="categoryName" class="col-sm-2 control-label">分类 :</label>
<select id="categoryName" name="categoryName" class="col-sm-2 form-control" style="width: auto;margin-left: 15px">
<option value="ca0001" selected="">计算机</option>
<option value="ca0002">文学</option>
<option value="ca0003">历史</option>
<!-- 下拉列表的内容要从分类中进行读取,value值是分类id -->
</select>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">价格 :</label>
<div class="col-sm-8">
<input name="bookPrice" class="form-control" id="bookPrice">
</div>
</div>
<div class="form-group" >
<label for="name" class="col-sm-2 control-label">图书封面 :</label>
<input type="file" id="bookPic" name="bookPic" style="padding-left: 15px">
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">备注 :</label>
<div class="col-sm-8">
<input name="remarks" class="form-control" id="remarks">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">修改</button>
</div>
</div>
</form>
</div>
<footer class="text-center" >
copy@imooc
</footer>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新建图书信息</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/add.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/dept/list.do">
图书信息管理
</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, XXX!</h1>
<p>请小心地新增图书信息,要是建了一个错误的就不好了。。。</p>
</div>
<div class="page-header">
<h3><small>新建</small></h3>
</div>
<form class="form-horizontal" enctype="multipart/form-data" action="${pageContext.request.contextPath }/AddBookServlet" method="post">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">图书编号 :</label>
<div class="col-sm-8">
<input name="bookId" class="form-control" id="bookId">
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">图书名称 :</label>
<div class="col-sm-8">
<input name="bookName" class="form-control" id="bookName">
</div>
</div>
<div class="form-group">
<label for="categoryId" class="col-sm-2 control-label">分类 :</label>
<select id="categoryId" name="categoryId" class="col-sm-2 form-control" style="width: auto;margin-left: 15px">
<option value="计算机" selected="">计算机</option>
<option value="文学">文学</option>
<option value="历史">历史</option>
<!-- 下拉列表的内容要从分类中进行读取,value值是分类id -->
</select>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">价格 :</label>
<div class="col-sm-8">
<input name="bookPrice" class="form-control" id="bookPrice">
</div>
</div>
<div class="form-group" >
<label for="name" class="col-sm-2 control-label">图书封面 :</label>
<input type="file" id="bookPic" name="bookPic" style="padding-left: 15px">
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">备注 :</label>
<div class="col-sm-8">
<input name="remarks" class="form-control" id="remarks">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</div>
</form>
</div>
<footer class="text-center" >
copy@imooc
</footer>
</body>
</html>
package com.imooc.web.servlet;
import java.io.IOException;
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.imooc.domain.Book;
import com.imooc.impl.BookServiceImpl;
import com.imooc.service.BookService;
@WebServlet("/SerchBookServlet")
public class SerchBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接收数据
String bookId=request.getParameter("bookId");
//封装数据
BookService bookService=new BookServiceImpl();
//处理数据
Book thisbook=bookService.getBooksById(bookId);
request.getSession().setAttribute("thisbook", thisbook);
response.sendRedirect(request.getContextPath()+"/updateBook.jsp");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
/**
* 图书信息处理类BookServiceImpl:
类型描述:能够描述图书信息,private static final List<Book> books;
方法:
添加图书信息:public void addBook(Book book) {}
修改图书信息:public void updateBook(Book book) {}
删除图书信息:public void deleteBook(String bookId) {}
根据图书ID来查询书籍信息:public Book getBooksById(String bookID) {}
根据分类来查询书籍信息:public List<Book> getBooksByCatgoryName(String catgoryName) {}
* */
package com.imooc.impl;
import java.util.ArrayList;
import java.util.List;
import com.imooc.domain.Book;
import com.imooc.service.BookService;
public class BookServiceImpl implements BookService{
private static final List<Book> books=new ArrayList<Book>();
public static List<Book> getBooks() {
return books;
}
// 添加图书信息
@Override
public void addBook(Book book) {
books.add(book);
}
//修改图书信息
@Override
public void updateBook(Book book) {
deleteBook(book.getBid());
books.add(book);
}
//删除图书信息
@Override
public void deleteBook(String bookId) {
for(Book book:books) {
if(book.getBid().equals(bookId)) {
books.remove(book);
break;
}
}
}
//根据图书ID来查询书籍信息
@Override
public Book getBooksById(String bookID) {
for(Book book:books) {
if(book.getBid().equals(bookID)) {
return book;
}
}
return null;
}
//根据分类来查询书籍信息
@Override
public List<Book> getBooksByCatgoryName(String catgoryName) {
List<Book> bookList=new ArrayList<Book>();
for(Book book:books) {
if(book.getBcategory().equals(catgoryName)) {
bookList.add(book);
}
}
return null;
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星