This commit is contained in:
Kane 2022-08-23 22:36:08 +08:00
parent 303e6b069e
commit 35aa1a8453
10 changed files with 208 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

View File

@ -0,0 +1,74 @@
<?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>com.cpic.xim</groupId>
<artifactId>tomcat-servlet</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>tomcat-servlet Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/servlet-api.jar</systemPath>
</dependency>
</dependencies>
<build>
<finalName>tomcat-servlet</finalName>
<pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,47 @@
/*
* @Author: Kane
* @Date: 2022-08-23 21:28:26
* @LastEditors: Kane
* @LastEditTime: 2022-08-23 22:32:48
* @FilePath: \tomcat-servlet\src\main\java\com\cpic\xim\ServletTest.java
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
package com.cpic.xim;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
public class ServletTest extends HttpServlet
{
@Override
public void doGet( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
PrintWriter writer = response.getWriter();
HttpSession session = request.getSession();
String sessionID = session.getId();
response.setContentType( "text/html" );
writer.write( "<!DOCTYPE html>" );
writer.write( "<html lang=\"en\">" );
writer.write( "<head>" );
writer.write( "<meta charset=\"UTF-8\" />" );
writer.write( "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />" );
writer.write(
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />" );
writer.write( "<title>学习JSP</title>" );
writer.write( "</head>" );
writer.write( "<body>" );
writer.write( "我的Session-ID是" + sessionID );
writer.write( "</body>" );
writer.write( "</html>" );
writer.write( " " );
}
}

View File

@ -0,0 +1,15 @@
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>ServletTest</servlet-name>
<servlet-class>com.cpic.xim.ServletTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,24 @@
<!--
* @Author: Kane
* @Date: 2022-08-23 21:26:04
* @LastEditors: Kane
* @LastEditTime: 2022-08-23 21:51:29
* @FilePath: \tomcat-servlet\src\main\webapp\index.jsp
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<a href="./test">访问servlet</a>
</body>
</html>

View File

@ -0,0 +1,4 @@
#Created by Apache Maven 3.8.5
artifactId=tomcat-servlet
groupId=com.cpic.xim
version=1.0-SNAPSHOT

View File

@ -0,0 +1 @@
D:\develop\study\servlet-learning\tomcat-servlet\tomcat-servlet\src\main\java\com\cpic\xim\ServletTest.java

View File

@ -0,0 +1,15 @@
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>ServletTest</servlet-name>
<servlet-class>com.cpic.xim.ServletTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,24 @@
<!--
* @Author: Kane
* @Date: 2022-08-23 21:26:04
* @LastEditors: Kane
* @LastEditTime: 2022-08-23 21:51:29
* @FilePath: \tomcat-servlet\src\main\webapp\index.jsp
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<a href="./test">访问servlet</a>
</body>
</html>