项目结构
这是index.html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="/brand_demo/selectAllServlet">查询所有</a>
</body>
</html>
这是brand.jsp代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="button" value="新增" id="add"><br>
<hr>
<table border="1" cellspacing="0" width="80%">
<tr>
<th>序号</th>
<th>品牌名称</th>
<th>企业名称</th>
<th>排序</th>
<th>品牌介绍</th>
<th>状态</th>
<th>操作</th>
</tr>
<c:forEach items="${brands}" var="brand" varStatus="status">
<tr align="center">
<%--<td>${brand.id}</td>--%>
<td>${status.count}</td>
<td>${brand.brandName}</td>
<td>${brand.companyName}</td>
<td>${brand.ordered}</td>
<td>${brand.description}</td>
<c:if test="${brand.status == 1}">
<td>启用</td>
</c:if>
<c:if test="${brand.status != 1}">
<td>禁用</td>
</c:if>
<td><a href="/brand_demo/selectByIdServlet?id=${brand.id}">修改</a> <a href="#">删除</a></td>
</tr>
</c:forEach>
</table>
<script>
document.getElementById("add").onclick = function (){
location.href = "/brand_demo/addBrand.jsp";
}
</script>
</body>
</html>
SelectAllServlet代码
package com.test.web;
import com.test.pojo.Brand;
import com.test.service.BrandService;
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 javax.swing.*;
import java.io.IOException;
import java.util.List;
@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {
private BrandService service=new BrandService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.调用BrandService完成查询
List<Brand> brands = service.selectAll();
//2.存入request域中
request.setAttribute("brands",brands);
//3.转发到brand.jsp
request.getRequestDispatcher("/brand.jsp").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
}
}
运行结果及报错内容
"C:\Program Files\Java\jdk1.8.0_212\bin\java.exe" -Dcatalina.home=E:\apache-tomcat-8.5.82 -Dcatalina.base=C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo -Djava.io.tmpdir=C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo\temp -Djava.util.logging.config.file=C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo\conf\logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager "-javaagent:E:\java\idea\IntelliJ IDEA Educational Edition 2021.3.1\lib\idea_rt.jar=57499:E:\java\idea\IntelliJ IDEA Educational Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath E:\apache-tomcat-8.5.82\bin\bootstrap.jar;E:\apache-tomcat-8.5.82\bin\tomcat-juli.jar org.apache.catalina.startup.Bootstrap start
22-Sep-2022 16:45:47.326 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/8.5.82
22-Sep-2022 16:45:47.331 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Aug 8 2022 21:26:07 UTC
22-Sep-2022 16:45:47.331 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号: 8.5.82.0
22-Sep-2022 16:45:47.331 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Windows 10
22-Sep-2022 16:45:47.331 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 10.0
22-Sep-2022 16:45:47.331 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd64
22-Sep-2022 16:45:47.331 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: C:\Program Files\Java\jdk1.8.0_212\jre
22-Sep-2022 16:45:47.332 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 1.8.0_212-b10
22-Sep-2022 16:45:47.332 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation
22-Sep-2022 16:45:47.332 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo
22-Sep-2022 16:45:47.333 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: E:\apache-tomcat-8.5.82
22-Sep-2022 16:45:47.333 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.home=E:\apache-tomcat-8.5.82
22-Sep-2022 16:45:47.333 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.base=C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo
22-Sep-2022 16:45:47.333 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.io.tmpdir=C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo\temp
22-Sep-2022 16:45:47.334 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.config.file=C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo\conf\logging.properties
22-Sep-2022 16:45:47.334 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
22-Sep-2022 16:45:47.334 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -javaagent:E:\java\idea\IntelliJ IDEA Educational Edition 2021.3.1\lib\idea_rt.jar=57499:E:\java\idea\IntelliJ IDEA Educational Edition 2021.3.1\bin
22-Sep-2022 16:45:47.334 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dfile.encoding=UTF-8
22-Sep-2022 16:45:47.334 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 在java.library.path:[C:\Program Files\Java\jdk1.8.0_212\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;F:\python\Scripts\;F:\python\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk1.8.0_301\bin;C:\Program Files\Java\jdk1.8.0_301\jre\bin;C:\Program Files\Java\jdk1.8.0_301\bin;C:\Program Files\Java\jdk1.8.0_301\jre\bin;C:\Bandizip\;C:\Program Files\dotnet\;D:\Bandizip\;E:\Node\;E:\mysql-8\mysql-8.0.28-winx64\bin;E:\apache-maven-3.8.6\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;;F:\vscode\Microsoft VS Code\bin;C:\Users\Administrator\.dotnet\tools;C:\Users\Administrator\AppData\Roaming\npm;.]上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中获得最佳性能
22-Sep-2022 16:45:47.535 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-8080"]
22-Sep-2022 16:45:47.564 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 816 ms
22-Sep-2022 16:45:47.606 信息 [main] org.apache.catalina.core.StandardService.startInternal 正在启动服务[Catalina]
22-Sep-2022 16:45:47.606 信息 [main] org.apache.catalina.core.StandardEngine.startInternal 正在启动 Servlet 引擎:[Apache Tomcat/8.5.82]
22-Sep-2022 16:45:47.622 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor 正在部署部署描述符[C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo\conf\Catalina\localhost\brand_demo.xml]。
22-Sep-2022 16:45:48.334 警告 [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom 使用[SHA1PRNG]创建会话ID生成的SecureRandom实例花费了[324]毫秒。
22-Sep-2022 16:45:48.372 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor 部署描述符[C:\Users\Administrator\.SmartTomcat\brand_demo\brand_demo\conf\Catalina\localhost\brand_demo.xml]的部署已在[749]ms内完成
22-Sep-2022 16:45:48.376 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]
22-Sep-2022 16:45:48.487 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 922 ms
http://localhost:8080/brand_demo
然后我点下面链接报404
这是我tomcat的配置