web.xml 的加载顺序是:context- param -> listener -> filter -> servlet

* Servlet

对URL生效,用户处理用户的URL请求,流程是短的,处理完转到指定页面即结束;

* Filter

对URL生效,响应用户请求(Servlet、Action、HTML、JSP等处理前)前做过滤,线性结构,处理完后,请求交给下一个Filter或者Action处理;

常用场景:字符编码、用户登陆的权限控制等;

* Listener

定义在web.xml中,用于对容器的相关事件做监听,如ContextLoaderListener,在Context加载完后触发;

servlet2.4规范中提供了8个listener接口,可以将其分为三类,分别如下: 
第一类:与servletContext有关的listner接口。包括:ServletContextListener、ServletContextAttributeListener 
第二类:与HttpSession有关的Listner接口。包括:HttpSessionListner、HttpSessionAttributeListener、HttpSessionBindingListener、HttpSessionActivationListener; 
第三类:与ServletRequest有关的Listener接口,包括:ServletRequestListner、ServletRequestAttributeListener

* Interceptor

定义在struts.xml中,不是针对URL做过滤,而是对Action请求做拦截处理;

常用场景:事务管理,DB读写分离,分库管理;

struts2中的过滤器和拦截器的区别与联系:

(1)拦截器是基于java反射机制的,而过滤器是基于函数回调的。 
 (2)过滤器依赖与servlet容器,而拦截器不依赖与servlet容器。 
 (3)拦截器只能对Action请求起作用,而过滤器则可以对几乎所有请求起作用。 
 (4)拦截器可以访问Action上下文、值栈里的对象,而过滤器不能。

----------------------------------------------------------------------------------------------------------

1、servlet:

2、filter:

3、listener:

4、interceptor:

servlet & filter & listener & interceptor的更多相关文章

  1. servlet filter listener interceptor 知识点

    这篇文章主要介绍 servlet filter listener interceptor 之 知识点.博文主要从 概念,生命周期,使命介绍其区别.详情如下:   概念 生命周期 使命 servlet ...

  2. servlet/filter/listener/interceptor区别与联系

    转自:http://www.cnblogs.com/doit8791/p/4209442.html servlet.filter.listener是配置到web.xml中(web.xml 的加载顺序是 ...

  3. 【转】servlet/filter/listener/interceptor区别与联系

    原文:https://www.cnblogs.com/doit8791/p/4209442.html 一.概念: 1.servlet:servlet是一种运行服务器端的java应用程序,具有独立于平台 ...

  4. [转]web.xml中servlet ,filter ,listener ,interceptor的作用与区别

    原文链接:https://blog.csdn.net/netdevgirl/article/details/51483273 一.概念: 1.servlet:servlet是一种运行服务器端的java ...

  5. JavaWeb三大组件(Servlet,Filter,Listener 自己整理,初学者可以借鉴一下)

    JavaWeb三大组件(Servlet,Filter,Listener 自己整理,初学者可以借鉴一下) Reference

  6. SpringBoot学习笔记(6)----SpringBoot中使用Servlet,Filter,Listener的三种方式

    在一般的运用开发中Controller已经大部分都能够实现了,但是也不排除需要自己实现Servlet,Filter,Listener的方式,SpringBoot提供了三种实现方式. 1. 使用Bean ...

  7. ServletContextInitializer添加 servlet filter listener

    ServletContextInitializer添加 servlet filter listener https://www.cnblogs.com/pomer-huang/p/9639322.ht ...

  8. SpringBoot---注册Servlet,Filter,Listener

    1.概述 1.1.当使用  内嵌的Servlet容器(Tomcat.Jetty等)时,将Servlet,Filter,Listener  注册到Servlet容器的方法: 1.1.1.直接注册Bean ...

  9. filter listener interceptor的区别

    转自: http://www.cnblogs.com/shangxiaofei/p/5328377.html https://www.cnblogs.com/jinb/p/6915351.html 一 ...

随机推荐

  1. 【转】C 宏

    http://www.cs.yale.edu/homes/aspnes/pinewiki/C%282f%29Macros.html See KernighanRitchie Appendix A12. ...

  2. 转载: SQL Server中的索引

    http://www.blogjava.net/wangdetian168/archive/2011/03/07/347192.html 1 SQL Server中的索引 索引是与表或视图关联的磁盘上 ...

  3. POM的配置文件

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. 【题解】【数组】【Leetcode】Merge Sorted Array

    Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...

  5. 232. Implement Queue using Stacks

    Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...

  6. Scrum第一天任务认领情况

    在团队项目“广商百货”的SCRUM项目中我认领的任务是对登录注册界面进行完善.具体功能还没有实现,还在学习中...

  7. hdu4642 Fliping game ——博弈

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4642 refer to: http://www.cnblogs.com/jackge/archive/ ...

  8. [luogu P2170] 选学霸(并查集+dp)

    题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...

  9. centOS 6.x 版本安装 node.js 4.x 以上版本的方法

    由于 node 4.x 以上版本,通过编译源代码来安装,对 GCC 的版本有要求,而 centos 的 GCC 版本不够,更新 GCC 也很麻烦,所以只能通过别的方式解决. 这里主要介绍直接下载编译后 ...

  10. linux下crontab定时执行本地脚本和定时访问指定url

    https://my.oschina.net/u/2487410/blog/683308 使用linux curl命令讲解:http://www.linuxdiyf.com/linux/2800.ht ...