• Post Reply Bookmark Topic Watch Topic
  • New Topic

Single controller vs Filter

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under what circumstances is Single controller better than filters and vice-versa?
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradeep,
I am not able to understand what exactly you mean by "Single controller". How would we implement it?
Single controller would become webserver specific implementation I guess if we don't use Servlet Filters and believe me thats not we want to do. I had this C module on iPlanet webserver that does that Single Controlling for implementing central code to protect all resources and I can't move that across machines just like that as I have to re-compile the module on different platforms (Solaris to Linux flavors etc)...
I am not sure what else you might be referring to via "Single controller" term..
to me- Filtering is the single controller.
Regards,
Maulin
 
Juan Rolando Prieur-Reza
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maulin Vasavada:
not sure what else you might be referring to via "Single controller" term

Pardon my intrusion but I would also like to have a common understanding of the terms, "filters" versus "single controller".
My understanding would be like this...
A filter pattern would involve several JSPs which forward or redirect from one to another until some condition caused or detected in one of them; no single JSP (i.e. implicit servlet) performs the test-and-forward. In contrast, a "single controller" would involve a servlet that constructs any one of a number of possible pages from fragments; it my take the form of a single JSP or an explicit servlet, but is organized so as to produce distinct "pages" based on conditions.
I welcome any corrections or opinions.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maulin Vasavada:
Hi Pradeep,
I am not sure what else you might be referring to via "Single controller" term..
to me- Filtering is the single controller.
Regards,
Maulin

Filters are located between MVC and the client. They pre-process the request and post-process the response, according to each client. They are, in another way, Request-Response Interceptors.
But for Single Controller, I guess Pradeep mean to "Front Controller"... Do u, Pradeep?
Actually they do their tasks differently...
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant the Front controller. There are functionalities like session tracking which can be done both in the servlet as well as filters. So which one to use?
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep, for me, I use Servlets to control session tracking... Filters are used for only pre-processing of the requests and pre-processing of the responses...
Actually they do diffrent tasks, don't they? What's your opinion, Pradeep? Which one do you use for session tracking???
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wron in using session tracking in a filter. If I am not wrong JAVA petstore has a logic for checking whether the user had logged in when a protected page is accessed. If the user is not logged in (session not created) he/she is redirected to login page.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
What is wron in using session tracking in a filter. If I am not wrong JAVA petstore has a logic for checking whether the user had logged in when a protected page is accessed. If the user is not logged in (session not created) he/she is redirected to login page.

Actually that is Front Controller's job, isn't it? I think both of us are using terms on what we want to talk about...
As for me, filters are under Request-Response Interceptors' components and Front Controllers as well as Servlets are under "Controller" of MVC architecture...
I'm not quite clear with the word "filter" you use...
I'm not sure that filter you are talking about is referring to Request-Response Interceptors' components, which pre-process requests and post-process responses (or) Front Controller which controls the workflow of a web application....
I think we both got different usage of J2EE terminology...
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KO KO,
http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html
Read the line
Has the client been authenticated.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:

Read the line
Has the client been authenticated.

Is it not pre-processing the request?
Later processing of the request is the responsibilty of Front Controllers or Servlets...
It says
When a request enters a Web application, it often must pass several entrance tests prior to the main processing stage.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just wondering what can go into controler ?
Services like login , logging can all go into Filters. Controller will just have to take care of processing the request.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
I was just wondering what can go into controler ?
Services like login , logging can all go into Filters. Controller will just have to take care of processing the request.

Yes, you are right... It's a nice discuss, isn't it?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel Filters can take care of all system services like authentication.
The advantage of Filters over servlet controllers is that it can plugged at any point of time without disturbing other parts of the application.

I see a lot of smileys in you posts. You sure have lots of reasons to smile. Hope I had some.
[ November 14, 2003: Message edited by: Pradeep Bhat ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!