---
title: "Servlet3.0 增加的几个标签"
author: "tntxia"
date: "2017-10-16T22:32:38Z"
tags: []
categories: ["Web前端"]
slug: "servlet3-0"
draft: false
lastmod: "2017-10-16T22:27:40Z"
id: 2396524
url: "https://tntxia.iteye.com/blog/2396524"
---

1. @WebFilter

 

```
@WebFilter("/*")
public class SessionFilter implements Filter {
     ...
}
```

 就可以轻松增加一个过滤器了。

 

2. @WebServlet

 

通过：

 

```
@WebServlet(
// Servlet的访问URL，可以使用数组的方式配置多个访问路径
urlPatterns = { "*.do", "*.mvc", "*.ftl" },
// Servlet的初始化参数
initParams = { @WebInitParam(name = "config-file", value = "/WEB-INF/config/mvc.xml") }, 
name = "mvc", description = "tntxia web mvc 入口Servlet")
public class DispatchServlet extends HttpServlet {
      ......

}
```

 

这种形式，我们可以轻松的增加Servlet，而不需要在Web.xml中配置Servlet信息

 

3. @WebListener

 

这个标签可以增加一个Listener，同样再也不需要webx.ml中增加Listener的配置了。

 

如：

```
@WebListener
public class InitListener implements ServletContextListener {
....
}
```

 

 总结：Servlet3.0增加的标签，使我们不需要使用web.xml，从而实现Web组件的可以插拔