This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Can filters be invoked AFTER servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can filters be invoked AFTER servlets?" Watch "Can filters be invoked AFTER servlets?" New topic
Author

Can filters be invoked AFTER servlets?

Qand Davaatsedev
Ranch Hand

Joined: Feb 06, 2002
Posts: 36
Following is a quote from "Hibernate in Action" book:

<quote>The job of the servlet filter is to close the Session before the
response is sent to the client (and after all views are rendered and actions are executed).</quote>

Is this approach feasible? As I understand, container invokes a filter BEFORE forwarding to a controller servlet. Can filters be invoked AFTER servlets and JSP pages finish their work to commit work and close Hibernate Session?


Qand
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
A filter sees the request BEFORE the servlet is called and the response AFTER the call returns from the servlet so the answer is yes. Take a look at the doFilter method in the javax.servlet.Filter interface.
Bill
Qand Davaatsedev
Ranch Hand

Joined: Feb 06, 2002
Posts: 36
Thank you, Bill.

Everything's clear now
 
wood burning stoves
 
subject: Can filters be invoked AFTER servlets?