(1) 下载好tomcat 10.1.28
打开tomcat.apache.org官网下载

(2)配置好maven

(3)idea 2024打开,建立项目
选择maven java项目

(4)在项目src/main/下
建立webapp/WEB-INF目录,在此目录下建立web.xml文件
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
</web-app>

(5)修改maven pom.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.webrx</groupId>
<artifactId>mweb6</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- jakarta.servlet.jsp-api -->
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
(6)配置tomcat本地服务器


部署项目设置

设置完成后效果

(7)webapp 就是jsp项目根目录
建立index.jsp首页文件
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>servlet 4.0.1 demo</title>
</head>
<body>
<h1>${pageContext.servletContext.serverInfo}</h1>
<h2>Servlet ${pageContext.servletContext.majorVersion}.${pageContext.servletContext.minorVersion}</h2>
<h2>${pageContext.request.contextPath}</h2>
<h2>${pageContext.request.method}</h2>
<h2><%=System.getProperty("java.version")%></h2>
<h2><%=System.getProperty("java.home")%></h2>
<h2><%=System.getProperty("os.name")%></h2>
<h2><%=String.format("%1$tF %1$tT", System.currentTimeMillis())%></h2>
</body>
</html>
(8)idea中debug方式启动项目

热部署配置

(9)浏览效果

(10)项目结果说明


1151

被折叠的 条评论
为什么被折叠?



