This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Filters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "Filters" Watch "Filters" New topic


sitaram irrinki
Ranch Hand

Joined: Feb 16, 2005
Posts: 158
while i am working with FILTERS in java,

1) Is it compulsary to have a servlet when working with filter and

2) if i want to call a specific servlet using filters then how should we proceed.

please explain me with an example if possible along with deployment descriptor
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
No it's not mandatory to have a servlet in order to use a filter.

Say we have a filter:


This will filter ALL requests received, irrespective of the resource requested. Images, pages, stylesheets, the works.

I'm not entirely sure what you ment by calling a servlet using a filter, but I suspect you either want to redirect to the servlet url, or request a servlet resource while processing a user request.

1) Redirecting:
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException

2) Requesting a servlet:
{ url = new"htpp://myserver/myServlet.go");
InputStream myStream = url.openStream();
//Code to read servlets' response from the myStream InputStream

We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Filters
It's not a secret anymore!