idea之映射servlet問題

方式一:

配置web.xml以下節點,事例以下:html

servlet>  
    <servlet-name>HelloWorld</servlet-name>  
    <servlet-class>HelloWorld</servlet-class>  
</servlet>  
  
<servlet-mapping>  
    <servlet-name>HelloWorld</servlet-name>  
    <url-pattern>/HelloWorld</url-pattern>  
</servlet-mapping>  

方式二:

用註解來實現映射servlet,@WebServlet(urlPatterns = {"/abc"})java

由於須要用到註解,因此web.xml只須要配置一次,之後就不用配置了web

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         metadata-complete="false" version="3.0">
    <display-name>Archetype Created Web Application</display-name>
</web-app>

而後,就在你本身的servlet中配置一下地,截圖以下:app

其實第二種就是Servlet3.0新特性,參考資料以下:url

http://www.cnblogs.com/heyongjun1997/p/6080145.htmlspa

以上兩種方式都是能夠的,各位能夠本身試試。若是不行的話,咋們能夠討論討論,再見。3d

相關文章
相關標籤/搜索