wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet Filter Confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Filter Confusion" Watch "Servlet Filter Confusion" New topic
Author

Servlet Filter Confusion

Ram Chhabra
Ranch Hand

Joined: Jan 07, 2008
Posts: 48
Hi,

I have created one filter. What i want that once control come to Filter, i need to do some validations and if it passes that validation then only i need to call chain.doFilter(res, req) but if validation fails then i don't want that request goes to servlet.

Can i send response from Filter only to client, without going to specific servlet.?

Thanks
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
I think you can do it this way...



Regards,
Vishwa


Blog
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
Yes. you should be able to control if the filter should continue the response or not.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Ram Chhabra
Ranch Hand

Joined: Jan 07, 2008
Posts: 48
Thanks for your reply. Inspite of sending to error page, is it ok to create the Response object and send back to client from filter only.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

I would not generate output in a filter -- that's not its intent. Rather forward or redirect to whatever resource (JSP or servlet) will gneerate the desired response.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Filter Confusion
 
Similar Threads
Filter configuration?
javascript-AJAX regarding
Spring portlet MVC forms, multipart data and servlets?
OK to read the request body within a filter?
Interview question: What's the difference between and Servlet and Filter?