• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems about Filters in Servlets

 
Ranch Hand
Posts: 59
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



This is the doFilter method to display header and footer to a servlet. iam not able to understand HOW is the chain.doFilter(request,response) method able to stop the footer from being printed right below the header. what is it actually doing ? because a filter can pass control to a servlet by using it but a servlet doesnt come back to filter?
also what is the exact difference between a chain.doFilter() and the do Filter method with a chain arguement?

Thanks very much :-)
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aashima Arora wrote:because a filter can pass control to a servlet by using it but a servlet doesnt come back to filter?



Yes it does - that's the key point. The filter gets the request on the way in. When it calls chain.doFilter(), that passes the request on to the next filter in line, and eventually to the servlet. Then, when the servlet has finished processing, the processing passes back through all the filters (in reverse order).
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...

you should not use the Filter for the Printing purpose.Filter must be used for Session checking and scanning the the incoming the HttpRequest
in very high security websites.
coming to your Question
when your Filter is fired with URL pattren Automaticlly Server will call the doFilter() Method with Required Arguments
Request and Response chain.
you need to some sort of validations after completion successful the request should go to the Original Resource. like this chain.doFilter(request,response);
if not we will redirct to another page in the doFilter Method only.
response.sendRedrict("error.jsp"); like this..

i hope i gave you the answer if not please rise the Query..

Thanks,
Ramakrishna Rayudu
 
Aashima Arora
Ranch Hand
Posts: 59
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Matthew : Ohhh !! yes..so by that you mean when the chain.doFilter(..) method is called, the control is passed to the next filter or the servlet and when the servlet has generated a response, it comes back to doFilter(..) method and executes the statements beneath it ? is that what iam supposed to get??
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, yeah. That's normally how calling a method works. I can't imagine why you decided that servlets would somehow be different. It's just Java code after all.
 
Aashima Arora
Ranch Hand
Posts: 59
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just burst my bubble...true , i dont know what was i thinking before asking such a question
thanks !
 
reply
    Bookmark Topic Watch Topic
  • New Topic