Configuring Servlets using annotations and configuring Servlets in web.xml

Configure in web.xml

insert image description here

<servlet>
<!--    Servlet的名字-->
    <servlet-name>hello</servlet-name>
<!--    Servlet类-->
    <servlet-class>com.hrbu.web.HelloServlet</servlet-class>
  </servlet>
<!--  映射-->
  <servlet-mapping>
<!--    与上面的保持一致-->
    <servlet-name>hello</servlet-name>
<!--    url,注意要以/开头-->
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>

The access effect is the same as before

Configuring Servlets Using Annotations

insert image description here
As shown in the figure, the access effect is the same, and the name attribute here is not necessary.

The two configuration methods have their own advantages and disadvantages, Baidu.

Guess you like

Origin blog.csdn.net/weixin_53236380/article/details/127423900