| Author |
Thinking about filters, again.
|
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Hi. Shamefully, there is something I don't understand about Servlets filters... My basic idea of filters : If the request satifies your requirements, allow it to hit the resource (you know, chain.doFilter), if not, return from the method. But recently, I found this snippet from Hibernate CaveatEmptor: How the hell they put another statement after doFilter( ) call ?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
doFilter() is a Java method like any other. When it completes, it returns and execution continues from the point of call. Why should this surprise you? [ April 04, 2007: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
John, There are three basic patterns for filters. 1) Execute filter before rest of request. Good for restricting access. // do filter stuff chain.doFilter(request, response); 2) Execute filter after rest of request. Good for post processing of response. chain.doFilter(request, response); // do filter stuff 3) Execute request in between filter. Good for more complex filters like the open source compression filter. // do filter stuff chain.doFilter(request, response); // do more filter stuff I'm assuming that Hibernate is an example of case 3 where they make sure every request is in a transaction. (What I'm assuming is that they begin the transaction earlier in the filter.)
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
When it completes
completes here means, after (lets say) JSP had been rendered. right ?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
|
Correct. Remember this is all done in Java code, so all the usual Java rules apply.
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3359
|
|
Ok, lets say we have two filters : Filter one : Filter two : So, the workflow is as the following : - print 1 - filter1 chain.doFilter( ); - print 3 - filter2 chain.doFilter( ); - hit the JSP - print 4 - print 2 Right ? [ April 04, 2007: Message edited by: John Todd ]
|
 |
 |
|
|
subject: Thinking about filters, again.
|
|
|