wuheng vor 2 Jahren
Ursprung
Commit
4726f120eb

+ 3 - 0
.gitignore

@@ -45,3 +45,6 @@ nbdist/
 !*/build/*.java
 !*/build/*.html
 !*/build/*.xml
+
+
+production/*

+ 9 - 0
day04/pom.xml

@@ -53,5 +53,14 @@
 
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.opoo.maven</groupId>
+                <artifactId>tomcat9-maven-plugin</artifactId>
+                <version>3.0.0</version>
+            </plugin>
+        </plugins>
+    </build>
 
 </project>

+ 47 - 0
day08/src/com/lovecoding/servlet/DemoServlet.java

@@ -0,0 +1,47 @@
+package com.lovecoding.servlet;
+
+import javax.servlet.*;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * 假设说我在这里写业务代码
+ * 我们最终要展示给用户看
+ * 那么用户呢 只能看到 JSP 页面的HTML
+ */
+
+public class DemoServlet implements Servlet {
+
+    public void test(ServletResponse servletResponse) throws IOException {
+        /**
+         * 我们只需要在 web.xml 里面定义 URL 匹配路径 并指定Servlet 处理类
+         * 我们就可以接到前端的请求, web.xml 是Tomcat的配置档
+         */
+        System.out.println( "OK" );
+        PrintWriter writer = servletResponse.getWriter();
+        String msg = "<html> <body><h1> HELLO SERVLET!!!! </h1></body> </html>";
+        writer.print(msg);
+
+
+
+    }
+
+    @Override
+    public void init(ServletConfig servletConfig) throws ServletException {
+    }
+    @Override
+    public ServletConfig getServletConfig() {
+        return null;
+    }
+    @Override
+    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
+        test(servletResponse);
+    }
+    @Override
+    public String getServletInfo() {
+        return null;
+    }
+    @Override
+    public void destroy() {
+    }
+}

BIN
day08/web/WEB-INF/lib/servlet-api.jar


+ 18 - 0
day08/web/WEB-INF/web.xml

@@ -0,0 +1,18 @@
+<?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">
+
+
+    <servlet>
+        <servlet-name>Demo</servlet-name>
+        <servlet-class>com.lovecoding.servlet.DemoServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>Demo</servlet-name>
+        <url-pattern>/demo</url-pattern>
+    </servlet-mapping>
+
+
+</web-app>

+ 18 - 0
day08/web/index.jsp

@@ -0,0 +1,18 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: 武恒
+  Date: 2023/2/3
+  Time: 11:56
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+  <head>
+    <title>JSP demo页面</title>
+  </head>
+  <body>
+  <div>
+    <H1>HELLO TOMCAT!!!</H1>
+  </div>
+  </body>
+</html>