JavaWeb13.3【Tomcat&Servlet:Servlet(server applet)】

 

 

 

 

 

 

 

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 5          version="3.1">
 6 
 7     <!--配置Servlet-->
 8     <servlet>
 9         <servlet-name>demo1</servlet-name>
10         <servlet-class>com.haifei.servlet.ServletDemo1</servlet-class>
11     </servlet>
12     <servlet-mapping>
13         <servlet-name>demo1</servlet-name>
14         <url-pattern>/demo1</url-pattern>
15     </servlet-mapping>
16     
17 </web-app>
 1 package com.haifei.servlet;
 2 
 3 import javax.servlet.*;
 4 import java.io.IOException;
 5 
 6 /**
 7  * Servlet快速入门
 8  */
 9 public class ServletDemo1 implements Servlet{
10     @Override
11     public void init(ServletConfig servletConfig) throws ServletException {
12 
13     }
14 
15     @Override
16     public ServletConfig getServletConfig() {
17         return null;
18     }
19 
20     //提供服务
21     @Override
22     public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
23         System.out.println("hello servlet");
24         /*
25         在web.xml中配置好Servlet后
26         在浏览器地址栏http://localhost:8080/day13_tomcat_war_exploded/demo1每访问一次
27         IDEA控制台输出一次hello servlet
28          */
29     }
30 
31     @Override
32     public String getServletInfo() {
33         return null;
34     }
35 
36     @Override
37     public void destroy() {
38 
39     }
40 }

 

posted @ 2021-06-29 12:28  yub4by  阅读(47)  评论(0编辑  收藏  举报