SpringMVC-01
注释:通过 javax.servlet.http.HttpServlet; 创建
项目配置
1、New》Project
创建Empty ProJect
配置项目Maven,配置maven home path,配置文件路径,local repository
Name:SpringMVC_01
Catalog:internal
Archetype:org.apache.maven.archetypes:maven-archetype-webapp
D:\Users\Foamy\.jdks\corretto-1.8.0_382\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\Foamy\AppData\Local\Temp\archetypetmp -Djansi.passthrough=true -Dmaven.home=D:\Javaprogress\environment\apache-maven-3.8.8 -Dclassworlds.conf=D:\Javaprogress\environment\apache-maven-3.8.8\bin\m2.conf "-Dmaven.ext.class.path=D:\Program Files\JetBrains\IntelliJ IDEA 2023.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2023.2\lib\idea_rt.jar=60773:D:\Program Files\JetBrains\IntelliJ IDEA 2023.2\bin" -Dfile.encoding=UTF-8 -classpath D:\Javaprogress\environment\apache-maven-3.8.8\boot\plexus-classworlds-2.6.0.jar;D:\Javaprogress\environment\apache-maven-3.8.8\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2023.2 -s D:\Javaprogress\environment\apache-maven-3.8.8\conf\settings.xml -Dmaven.repo.local=D:\Javaprogress\environment\apache-maven-3.8.8\maven-pro -DinteractiveMode=false -DgroupId=com.msb -DartifactId=SpringMVC_01 -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.0 org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] Archetype repository not defined. Using the one from [org.apache.maven.archetypes:maven-archetype-webapp:1.0] found in catalog internal
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\Foamy\AppData\Local\Temp\archetypetmp
[INFO] Parameter: package, Value: com.msb
[INFO] Parameter: groupId, Value: com.msb
[INFO] Parameter: artifactId, Value: SpringMVC_01
[INFO] Parameter: packageName, Value: com.msb
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\Foamy\AppData\Local\Temp\archetypetmp\SpringMVC_01
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.953 s
[INFO] Finished at: 2023-08-20T15:35:09+08:00
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
目录结构
代码信息
MyServlet
package com.msb.controller;
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 java.io.IOException;
@WebServlet("/myServlet.do")
public class MyServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp ) throws ServletException{
try {
req.getRequestDispatcher("first.jsp").forward(req,resp);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
first.jsp
<%--
Created by IntelliJ IDEA.
User: Foamy
Date: 2023/8/20
Time: 15:37
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
this i fist.jsp
</body>
</html>
indes.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
web.xml
<?xml version="1.0" encoding = "UTF-8" ?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>
配置Tomcat
测试