Merge branch 'main' of http://222.76.244.118:3000/Kane/servlet-learning
This commit is contained in:
		
							
								
								
									
										3
									
								
								servlet-filter/filter-test/.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								servlet-filter/filter-test/.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "java.configuration.updateBuildConfiguration": "automatic"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										74
									
								
								servlet-filter/filter-test/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								servlet-filter/filter-test/pom.xml
									
									
									
									
									
										Normal 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>filter-test</artifactId>
 | 
				
			||||||
 | 
					  <version>1.0-SNAPSHOT</version>
 | 
				
			||||||
 | 
					  <packaging>war</packaging>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <name>filter-test 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>${pom.basedir}/src/main/webapp/WEB-INF/lib/servlet-api.jar</systemPath>
 | 
				
			||||||
 | 
					    </dependency>
 | 
				
			||||||
 | 
					  </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <build>
 | 
				
			||||||
 | 
					    <finalName>filter-test</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>
 | 
				
			||||||
@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * @Author: Kane
 | 
				
			||||||
 | 
					 * @Date: 2022-08-25 15:56:37
 | 
				
			||||||
 | 
					 * @LastEditors: Kane
 | 
				
			||||||
 | 
					 * @LastEditTime: 2022-08-25 15:57:04
 | 
				
			||||||
 | 
					 * @FilePath: \filter-test\src\main\java\com\cpic\xim\FilterTest.java
 | 
				
			||||||
 | 
					 * @Description:
 | 
				
			||||||
 | 
					 * Copyright (c) ${2022} by Kane, All Rights Reserved.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					package com.cpic.xim;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class FilterTest
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * @Author: Kane
 | 
				
			||||||
 | 
					 * @Date: 2022-08-25 16:08:43
 | 
				
			||||||
 | 
					 * @LastEditors: Kane
 | 
				
			||||||
 | 
					 * @LastEditTime: 2022-08-25 17:00:20
 | 
				
			||||||
 | 
					 * @FilePath: \filter-test\src\main\java\com\cpic\xim\servlets\ServletFilter.java
 | 
				
			||||||
 | 
					 * @Description: 
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package com.cpic.xim.servlets;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.io.PrintWriter;
 | 
				
			||||||
 | 
					import jakarta.servlet.ServletException;
 | 
				
			||||||
 | 
					import jakarta.servlet.http.HttpServlet;
 | 
				
			||||||
 | 
					import jakarta.servlet.http.HttpServletRequest;
 | 
				
			||||||
 | 
					import jakarta.servlet.http.HttpServletResponse;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class ServletFilter extends HttpServlet
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /*****************************************************
 | 
				
			||||||
 | 
					     * 
 | 
				
			||||||
 | 
					     * @param request
 | 
				
			||||||
 | 
					     * @param response
 | 
				
			||||||
 | 
					     * @exception ServletException
 | 
				
			||||||
 | 
					     *****************************************************/
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void doGet( HttpServletRequest request, HttpServletResponse response )
 | 
				
			||||||
 | 
					            throws ServletException, IOException
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // 设置一下contentType和编码
 | 
				
			||||||
 | 
					        response.setContentType( "text/html; charset=UTF-8" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 简单输出
 | 
				
			||||||
 | 
					        PrintWriter writer = response.getWriter();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        writer.write( "Get方法!!!!!!!!!\n" );
 | 
				
			||||||
 | 
					        writer.write( "测试增量更新!" );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								servlet-filter/filter-test/src/main/webapp/WEB-INF/web.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								servlet-filter/filter-test/src/main/webapp/WEB-INF/web.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					<!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>Servlet 过滤器学习!</display-name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- <welcome-file-list>
 | 
				
			||||||
 | 
					        <welcome-file>index.html</welcome-file>
 | 
				
			||||||
 | 
					    </welcome-file-list> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <servlet>
 | 
				
			||||||
 | 
					        <servlet-name>ServletFilter</servlet-name>
 | 
				
			||||||
 | 
					        <servlet-class>com.cpic.xim.servlets.ServletFilter</servlet-class>
 | 
				
			||||||
 | 
					    </servlet>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <servlet-mapping>
 | 
				
			||||||
 | 
					        <servlet-name>ServletFilter</servlet-name>
 | 
				
			||||||
 | 
					        <url-pattern>/filter-test</url-pattern>
 | 
				
			||||||
 | 
					    </servlet-mapping>
 | 
				
			||||||
 | 
					</web-app>
 | 
				
			||||||
							
								
								
									
										22
									
								
								servlet-filter/filter-test/src/main/webapp/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								servlet-filter/filter-test/src/main/webapp/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					<!--
 | 
				
			||||||
 | 
					 * @Author: Kane
 | 
				
			||||||
 | 
					 * @Date: 2022-08-25 16:11:38
 | 
				
			||||||
 | 
					 * @LastEditors: Kane
 | 
				
			||||||
 | 
					 * @LastEditTime: 2022-08-25 16:27:10
 | 
				
			||||||
 | 
					 * @FilePath: \filter-test\src\main\webapp\index.html
 | 
				
			||||||
 | 
					 * @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>学习过滤器</title>
 | 
				
			||||||
 | 
					    </head>
 | 
				
			||||||
 | 
					    <body>
 | 
				
			||||||
 | 
					        <a href="./filter-test">点击访问过滤器servlet!</a>
 | 
				
			||||||
 | 
					    </body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * @Author: Kane
 | 
				
			||||||
 | 
					 * @Date: 2022-08-25 15:03:05
 | 
				
			||||||
 | 
					 * @LastEditors: Kane
 | 
				
			||||||
 | 
					 * @LastEditTime: 2022-08-25 15:14:33
 | 
				
			||||||
 | 
					 * @FilePath: \tomcat-servlet\src\main\java\com\cpic\xim\AppListener.java
 | 
				
			||||||
 | 
					 * @Description: 
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					package com.cpic.xim;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import jakarta.servlet.ServletContext;
 | 
				
			||||||
 | 
					import jakarta.servlet.ServletContextEvent;
 | 
				
			||||||
 | 
					import jakarta.servlet.ServletContextListener;
 | 
				
			||||||
 | 
					import jakarta.servlet.annotation.WebListener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class AppListener implements ServletContextListener
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void contextInitialized( ServletContextEvent event )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        ServletContext context = event.getServletContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        context.setAttribute( "test", "test" );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void contextDestroyed( ServletContextEvent event )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 * @Author: Kane
 | 
					 * @Author: Kane
 | 
				
			||||||
 * @Date: 2022-08-23 21:28:26
 | 
					 * @Date: 2022-08-23 21:28:26
 | 
				
			||||||
 * @LastEditors: Kane
 | 
					 * @LastEditors: Kane
 | 
				
			||||||
 * @LastEditTime: 2022-08-25 14:19:05
 | 
					 * @LastEditTime: 2022-08-25 19:52:42
 | 
				
			||||||
 * @FilePath: \tomcat-servlet\src\main\java\com\cpic\xim\ServletTest.java
 | 
					 * @FilePath: \tomcat-servlet\src\main\java\com\cpic\xim\ServletTest.java
 | 
				
			||||||
 * @Description: 
 | 
					 * @Description: 
 | 
				
			||||||
 * 
 | 
					 * 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,4 +12,8 @@
 | 
				
			|||||||
    <url-pattern>/test</url-pattern>
 | 
					    <url-pattern>/test</url-pattern>
 | 
				
			||||||
  </servlet-mapping>
 | 
					  </servlet-mapping>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <!-- <listener>
 | 
				
			||||||
 | 
					    <listener-class>com.cpic.xim.AppListener</listener-class>
 | 
				
			||||||
 | 
					  </listener> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</web-app>
 | 
					</web-app>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user