package top.qaqaq.P128; /**
* @author RichieZhang
* @create 2022-12-04 下午 8:52
*/
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import java.io.IOException;
public class HelloServlet3 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("HelloServlet3的doGet方法");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("HelloServlet3的doPost方法");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!-- <form action="http://localhost:8080/JavaWeb_Code_Servlet/hello" method="get">-->
<!-- -->
<!-- <input type="submit">-->
<!-- </form>-->
<form action="http://localhost:8080/JavaWeb_Code_Servlet/hello3" method="post">
<input type="submit">
</form>
</body>
</html>
<?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标签给Tomcat配置Servlet程序 -->
<servlet>
<!--servlet-name标签 Servlet程序起一个别名(一般是类名)-->
<servlet-name>HelloServlet</servlet-name>
<!--servlet-class是Servlet程序的全类名)-->
<servlet-class>top.qaqaq.P122.HelloServlet</servlet-class>
</servlet>
<!-- servlet-mapping标签给servlet程序配置访问地址 -->
<servlet-mapping>
<!-- servlet-name标签的作用是告诉服务器,我当前配置的地址给哪个servlet程序使用 -->
<servlet-name>HelloServlet</servlet-name>
<!-- url-pattern标签配置访问地址
/ 斜杠在服务器解析的时候,表示地址为:http://ip:port/工程路径
/hello 表示地址为:http://ip:port/工程路径/hello
-->
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HelloServlet2</servlet-name>
<servlet-class>top.qaqaq.P127.HelloServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet2</servlet-name>
<url-pattern>/hello2</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HelloServlet3</servlet-name>
<servlet-class>top.qaqaq.P128.HelloServlet3</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet3</servlet-name>
<url-pattern>/hello3</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HelloServlet4</servlet-name>
<servlet-class>top.qaqaq.P130.HelloServlet4</servlet-class>
<!-- init-param是初始化参数 -->
<init-param>
<!-- 是参数名 -->
<param-name>username</param-name>
<!-- 是参数值 -->
<param-value>root</param-value>
</init-param>
<!-- init-param是初始化参数 -->
<init-param>
<!-- 是参数名 -->
<param-name>url</param-name>
<!-- 是参数值 -->
<param-value>jdbc:mysql://localhost:3306/test</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet4</servlet-name>
<url-pattern>/hello4</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HelloServlet5</servlet-name>
<servlet-class>top.qaqaq.P131.HelloServlet5</servlet-class>
<!-- init-param是初始化参数 -->
<init-param>
<!-- 是参数名 -->
<param-name>username</param-name>
<!-- 是参数值 -->
<param-value>root2</param-value>
</init-param>
<!-- init-param是初始化参数 -->
<init-param>
<!-- 是参数名 -->
<param-name>url</param-name>
<!-- 是参数值 -->
<param-value>jdbc:mysql://localhost:3306/test2</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet5</servlet-name>
<url-pattern>/hello5</url-pattern>
</servlet-mapping>
</web-app>