ch09
This commit is contained in:
@@ -3,6 +3,7 @@ package com.ycjy.Impl;
|
||||
import com.ycjy.interfaces.MyAppInit;
|
||||
import com.ycjy.servlet.FirstServlet;
|
||||
import com.ycjy.servlet.SecondServlet;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
|
||||
@@ -9,7 +9,7 @@ import jakarta.servlet.annotation.HandlesTypes;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Set;
|
||||
|
||||
//@HandlesTypes(MyAppInit.class) //告诉容器"把所有实现 MyAppInit 的类塞进 set"
|
||||
@HandlesTypes(MyAppInit.class) //告诉容器"把所有实现 MyAppInit 的类塞进 set"
|
||||
public class MyInit implements ServletContainerInitializer {
|
||||
@Override
|
||||
public void onStartup(Set<Class<?>> set, ServletContext ctx) throws ServletException {
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
package com.ycjy;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
//public class MyMvcAppInit implements WebApplicationInitializer {
|
||||
// @Override
|
||||
// public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
// // 基于注解配置的 Web 应用上下文简称容器
|
||||
// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
// context.setServletContext(servletContext);
|
||||
// context.register(MySystemConfig.class);
|
||||
// context.refresh(); // 刷新, 然后容器才开始真正去扫描包
|
||||
//
|
||||
// ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
|
||||
// DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
|
||||
//
|
||||
// ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
|
||||
// dispatcher.addMapping("/");
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.ycjy.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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>
|
||||
<parent>
|
||||
<groupId>com.linlangjz</groupId>
|
||||
<artifactId>SpringStudy</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Spring-ch10-backend</artifactId>
|
||||
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user