idea之映射servlet问题

方式一:

配置web.xml如下节点,事例如下:

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"})

因为需要用到注解,所以web.xml只需要配置一次,以后就不用配置了

<?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中配置一下地,截图如下:

其实第二种就是Servlet3.0新特性,参考资料如下:

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

以上两种方式都是可以的,各位可以自己试试。如果不行的话,咋们可以讨论讨论,再见。

posted on 2017-07-19 13:58  瞿亮  阅读(732)  评论(0编辑  收藏  举报

导航