• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

filters vs RequestDispatcher's include() method

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends can any one explain me what the main and exact difference between filters and RequestDispatcher's include() method?

some will say that filters are the preprocessors before they reach the servlets/jsps..
preprocessors means? preprocessors are those which will automatically do the entire work internally before the thing which we want to use is getting ready..
are they built automatically? or we should write the code?
if it was not automatic then why it is said to be preprocessor and why cant we use requestdispatcher in that case???

what is the difference between
--------------------------------------
code snippet:

pw.println("start in servlet 1");
requestdispatcher.include("/xxx);
pw.println("end in servlet 1");
---------------------------------------
Vs
------------------------------------
code snippet:

pw.println("start in filter 1");
filterchain.dofilter(request,response);
pw.println("end in filter 1");
---------------------------------------


and second one what is the use of filter chain concept??

suppose if above code is repeated in xxx.java,and in place of xxx if we replace yyy.java(say).. like this if we go on implementing.. we will get a chain using request dispatchers..

the only difference is we will place the order of filters in web.xml (<filter-mapping>) section.. so that filters execute in that order..

in request dispatcher we will call in the servlets as rd.include("/servlet or /jsp"); this will also form a chain in the order we mentioned in every servlet..

if not understood.. in detail with code:

using request dispatcher::

RD1.java:



Rd2.java:


RDA3.java:

web.xml:


the output is:

start in servlet 1
start in servlet 2
target servlet
end in servlet 2
end in servlet 1


using filters::

Filt1.java:





web.xml:



output is:

start in filter 1
start in filter 2
this is in target servlet
end in filter 2
end in filter 1

can any one please explain me the exact difference???

please help me friends..

i am very thankful to you if the answer is apt..

thanking you
sandeep kumar
 
Men call me Jim. Women look past me to this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic