图书修改的时候找不到ToUpdateBookServlet
bookList.jsp页面点击修改,报404错误,找不到servlet
HTTP状态 404 - 未找到
类型 状态报告
消息 请求的资源[/lm/ToUpdateBookServlet]不可用
描述 源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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">
</head>
<body>
<header>
<div class="container">
<nav>
<a href="bookList.jsp">图书信息管理</a>
</nav>
<nav>
<a href="categoryList.jsp">分类管理</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>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${requestScope.books}" var="book" varStatus="idx">
<!--
<tr id="tr1">
<td>1</td>
<td>book0001</td>
<td>Java基础</td>
<td>计算机类</td>
<td>¥29</td>
<td><img src="img/g1.jpg"></td>
<td>
<a href="/updateBook?bookId=book0001">修改</a>
<a href="/deleteBook?bookId=book0001">删除</a>
</td>
在循环显示数据时,此处的book0001可以用EL表达式进行替换
</tr>
-->
<tr>
<td>${idx.index+1}</td>
<td>${book.bookId}</td>
<td>${book.bookName}</td>
<td>${book.bookCategory}</td>
<td>${book.bookPrice}</td>
<td><img src=${book.bookPath }></td>
<td>${book.bookRemarks}</td>
<td><a
href="${pageContext.request.contextPath }/ToUpdateBookServlet?bookId=${book.bookId}">修改</a>
<a
href="${pageContext.request.contextPath }/DeleteBookServlet?bookId=${book.bookId}">删除</a>
</td>
<!--在循环显示数据时,此处的ca0001可以用EL表达式进行替换-->
</tr>
</c:forEach>
</tbody>
</table>
</div>
</section>
<section class="page">
<div class="container">
<div id="fatie">
<a href="${pageContext.request.contextPath}/ToAddBookServlet"><button>新建</button></a>
</div>
</div>
</section>
<footer> copy@慕课网 </footer>
</body>
</html>
++++++++++++++++++++++++++
package com.imooc.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.imooc.domain.Book;
import com.imooc.domain.Category;
import com.imooc.service.impl.BookServiceImpl;
import com.imooc.service.impl.CategoryServiceImpl;
@WebServlet("/ToUpdateBookServlet")
public class ToUpdateBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public ToUpdateBookServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获取页面提交的图书Id
String bookId=request.getParameter("bookId");
//处理数据
BookServiceImpl book=new BookServiceImpl();
book.getBooksById(bookId);
List<Category> categoryList=CategoryServiceImpl.getCategorydb();
request.setAttribute("book", book);
request.setAttribute("categoryList",categoryList);
//跳转到图书修改页面updateBook.jsp
request.getRequestDispatcher("/updateBook.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
正在回答 回答被采纳积分+1
<%
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath();
%>
我增加了一个这个basePath,
<a href="<%=basePath%>/ToUpdateBookServlet?bookId=${book.bookId}">修改</a>
然后又报错
HTTP状态 500 - 内部服务器错误
类型 异常报告
消息 javax.el.PropertyNotFoundException: 类型[com.imooc.service.impl.BookServiceImpl]上找不到属性[bookId]
描述 服务器遇到一个意外的情况,阻止它完成请求。
例外情况
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: 类型[com.imooc.service.impl.BookServiceImpl]上找不到属性[bookId]
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星