开发者

Java EE Servlet/filter/phase listener difference and order of processing

开发者 https://www.devze.com 2023-04-06 20:41 出处:网络
I want to know what the order of processing requests is and what\'s the difference between servlet (@WebSer开发者_开发问答vlet), filter (@WebFilter), phase listeners etc.

I want to know what the order of processing requests is and what's the difference between servlet (@WebSer开发者_开发问答vlet), filter (@WebFilter), phase listeners etc.

These methods have very similar headers (doGet/doFiler).


The processing of a request in regard to filtering and then processing by a servlet is described here:

http://download.oracle.com/docs/cd/B32110_01/web.1013/b28959/filters.htm

Thus you'd mainly use a servlet do deliver content and maybe alter request/response using filters. Filters can be used to implement a pipes and filters or a decorator design pattern. (Though they can also deliver content by themselves and don't forward delegation to final processing by a servlet at all.)

So much to the servlet request processing. PhaseListeners are a higher abstraction level concept. They don't belong to the servlet spec but to the Java Server Faces Concepts building ontop of servlets. They can be used to track the phases your JSF Components go through during a request and thus are the alternative for filters when you want to influence behaviour/rendering of JSF components during a request.

A litte example for the usage of phase listeners can be found here: http://www.softwareengineeringsolutions.com/thoughts/frameworks/JSF.Techniques-PhaseListeners.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消