zhang 2 роки тому
батько
коміт
e026f6c37b

+ 12 - 0
springMvc/pom.xml

@@ -59,6 +59,18 @@
59 59
       <artifactId>spring-webmvc</artifactId>
60 60
       <version>5.3.6</version>
61 61
     </dependency>
62
+    <dependency>
63
+      <groupId>javax.servlet</groupId>
64
+      <artifactId>javax.servlet-api</artifactId>
65
+      <version>4.0.1</version>
66
+      <scope>provided</scope>
67
+    </dependency>
68
+    <dependency>
69
+      <groupId>javax.servlet.jsp</groupId>
70
+      <artifactId>javax.servlet.jsp-api</artifactId>
71
+      <version>2.3.3</version>
72
+      <scope>provided</scope>
73
+    </dependency>
62 74
   </dependencies>
63 75
 
64 76
 </project>

+ 17 - 0
springMvc/src/main/java/web/UserServlet.java

@@ -0,0 +1,17 @@
1
+package web;
2
+
3
+import org.springframework.context.support.ClassPathXmlApplicationContext;
4
+
5
+import javax.servlet.ServletException;
6
+import javax.servlet.http.HttpServlet;
7
+import javax.servlet.http.HttpServletRequest;
8
+import javax.servlet.http.HttpServletResponse;
9
+import java.io.IOException;
10
+
11
+public class UserServlet extends HttpServlet {
12
+    @Override
13
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
14
+        //super.doGet(req, resp);
15
+        System.out.println("test");
16
+    }
17
+}

+ 23 - 0
springMvc/src/main/resources/context.xml

@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<beans xmlns="http://www.springframework.org/schema/beans"
4
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+       xmlns:context="http://www.springframework.org/schema/context"
6
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
7
+       http://www.springframework.org/schema/beans/spring-beans.xsd
8
+       http://www.springframework.org/schema/context
9
+       https://www.springframework.org/schema/context/spring-context.xsd">
10
+    <!--    <bean id="userService1" class="com.service.impl.UserServiceImpl">-->
11
+    <!--&lt;!&ndash;        <constructor-arg name="userDao" ref="UserDao"></constructor-arg>&ndash;&gt;-->
12
+    <!--    </bean>-->
13
+    <!--    加载外部 properties文件-->
14
+    <!--    <context:property-placeholder location="jdbc.properties"></context:property-placeholder>-->
15
+    <!--    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">-->
16
+    <!--        <property name="driverClassName" value="${jdbc.driver}"></property>-->
17
+    <!--        <property name="url" value="${jdbc.url}"></property>-->
18
+    <!--        <property name="username" value="${jdbc.username}"></property>-->
19
+    <!--        <property name="password" value="${jdbc.password}"></property>-->
20
+    <!--    </bean>-->
21
+    <!--    组件扫描-->
22
+    <context:component-scan base-package="com"></context:component-scan>
23
+</beans>

+ 5 - 83
springMvc/src/main/webapp/WEB-INF/web.xml

@@ -27,92 +27,14 @@
27 27
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
28 28
 
29 29
   <!-- Servlet Filters ================================================ -->
30
-
31
-  <!--
32
-    - Declare a filter for multipart MIME handling
33
-    -->
34
-  <filter>
35
-    <description>Multipart MIME handling filter for Cocoon</description>
36
-    <display-name>Cocoon multipart filter</display-name>
37
-    <filter-name>CocoonMultipartFilter</filter-name>
38
-    <filter-class>org.apache.cocoon.servlet.multipart.MultipartFilter</filter-class>
39
-  </filter>
40
-
41
-  <!--
42
-    - Declare a filter for debugging incoming request
43
-    -->
44
-  <filter>
45
-    <description>Log debug information about each request</description>
46
-    <display-name>Cocoon debug filter</display-name>
47
-    <filter-name>CocoonDebugFilter</filter-name>
48
-    <filter-class>org.apache.cocoon.servlet.DebugFilter</filter-class>
49
-  </filter>
50
-
51
-  <!-- Filter mappings ================================================ -->
52
-
53
-  <!--
54
-    - Use the Cocoon multipart filter together with the Cocoon demo webapp
55
-    -->
56
-  <filter-mapping>
57
-    <filter-name>CocoonMultipartFilter</filter-name>
58
-    <servlet-name>Cocoon</servlet-name>
59
-  </filter-mapping>
60
-  <filter-mapping>
61
-    <filter-name>CocoonMultipartFilter</filter-name>
62
-    <servlet-name>DispatcherServlet</servlet-name>
63
-  </filter-mapping>
64
-
65
-  <!--
66
-    - Use the Cocoon debug filter together with the Cocoon demo webapp
67
-  <filter-mapping>
68
-    <filter-name>CocoonDebugFilter</filter-name>
69
-    <servlet-name>Cocoon</servlet-name>
70
-  </filter-mapping>
71
-    -->
72
-
73
-  <!-- Servlet Context Listener ======================================= -->
74
-
75
-  <!--
76
-    - Declare Spring context listener which sets up the Spring Application Context
77
-    - containing all Cocoon components (and user defined beans as well).
78
-    -->
79
-  <listener>
80
-    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
81
-  </listener>
82
-
83
-  <!--
84
-    - Declare Spring request listener which sets up the required RequestAttributes
85
-    - to support Springs and Cocoon custom bean scopes like the request scope or the
86
-    - session scope.
87
-    -->
88
-  <listener>
89
-    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
90
-  </listener>
91
-
92
-  <!-- Servlet Configuration ========================================== -->
93
-
94
-  <!--
95
-    - Servlet that dispatches requests to the Spring managed block servlets
96
-    -->
97 30
   <servlet>
98
-    <description>Cocoon blocks dispatcher</description>
99
-    <display-name>DispatcherServlet</display-name>
100
-    <servlet-name>DispatcherServlet</servlet-name>
101
-    <servlet-class>org.apache.cocoon.servletservice.DispatcherServlet</servlet-class>
102
-    <load-on-startup>1</load-on-startup>
31
+    <servlet-name>User</servlet-name>
32
+    <servlet-class>web.UserServlet</servlet-class>
33
+    
103 34
   </servlet>
104
-
105
-  <!-- URL space mappings ============================================= -->
106
-
107
-  <!--
108
-    - Cocoon handles all the URL space assigned to the webapp using its sitemap.
109
-    - It is recommended to leave it unchanged. Under some circumstances though
110
-    - (like integration with proprietary webapps or servlets) you might have
111
-    - to change this parameter.
112
-    -->
113 35
   <servlet-mapping>
114
-    <servlet-name>DispatcherServlet</servlet-name>
115
-    <url-pattern>/*</url-pattern>
36
+    <servlet-name>User</servlet-name>
37
+    <url-pattern>/</url-pattern>
116 38
   </servlet-mapping>
117 39
 
118 40
 </web-app>

+ 1 - 12
spring_mvc/pom.xml

@@ -16,17 +16,6 @@
16 16
         <maven.compiler.target>8</maven.compiler.target>
17 17
     </properties>
18 18
     <dependencies>
19
-        <dependency>
20
-            <groupId>javax.servlet</groupId>
21
-            <artifactId>javax.servlet-api</artifactId>
22
-            <version>4.0.1</version>
23
-            <scope>provided</scope>
24
-        </dependency>
25
-        <dependency>
26
-            <groupId>javax.servlet.jsp</groupId>
27
-            <artifactId>javax.servlet.jsp-api</artifactId>
28
-            <version>2.3.3</version>
29
-            <scope>provided</scope>
30
-        </dependency>
19
+
31 20
     </dependencies>
32 21
 </project>