Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how one service() handles different requests???  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In MVC frameworks, Model holds business logic and it should be free from any *servlet related* objects like session, response etc because then no other client would be able to use this model.

But as usually happens, data comes in request or session, and if I want to do some processing on this data, I will take data in the servlet and then call any model's method that will give me result. Now I will add this result in request and will call forward() method for JSP. This is controller.

And JSP will render the result. This is view part.

I hope everything is right till this point.

But in MVC framework, there is only one servlet and all requests come to this servlet first. My doubt is how one service() method handles different-different requests?? (I am not confuse with thread model, container creates thread for each request, that is okay, but if two request is for two different job then how servlet (one service() method) differentiate and responds)

Please clear my doubt.
Thanks.
[ October 21, 2005: Message edited by: rathi ji ]
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a couple of answers to your questions. First, there is no requirement that you only use one servlet in the MVC pattern. You can map different requests to different servlets. For instance:


Second, there is a pattern that does route all requests to one servlet conrtoller. It is called "Front Controller" you would normall use this pattern when you want to avoid duplicate control logic, you want to allpy common logic to all the requests, or you want a centralized access point to your system. Struts is an example of the Front Controller design. Basically (very basically) all requests go to an action servlet that uses an external xml file to map the request to the appropriate components and views.
[ October 21, 2005: Message edited by: Paul Bourdeaux ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Bourdeaux:

there is a pattern that does route all requests to one servlet conrtoller. It is called "Front Controller" you would normall use this pattern when you want to avoid duplicate control logic, you want to allpy common logic to all the requests, or you want a centralized access point to your system. Struts is an example of the Front Controller design. Basically (very basically) all requests go to an action servlet that uses an external xml file to map the request to the appropriate components and views.




Could you please explain this in a bit detail.

If suppose there can be 5 types of request possible on my web site. I will map each request to a particular servlet in that external configuration file. But then why we need FrontController. 5 Servlet and one configuration file is enough to handle all request.

Please comments.
Thanks.
 
Amarender Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
=========================================================================
But then why we need FrontController. 5 Servlet and one configuration file is enough to handle all request.
=========================================================================

If thats fine then can u please explain me how would the external components (componenets outside your application ) will communicate with the configuration file?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amarender reddy:
=========================================================================
But then why we need FrontController. 5 Servlet and one configuration file is enough to handle all request.
=========================================================================

If thats fine then can u please explain me how would the external components (componenets outside your application ) will communicate with the configuration file?


Okay, so is it like this, every request comes to FrontController servlet then this FrontController servlet find out a particular servlet for that request from the configuration file and invoke that servlet...and so on...

am I right?
Thanks.
 
Amarender Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude!

excatly
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rathi,

On my site, http://simple.souther.us there are two examples that might help you with this.
The first is SimpleMVC, the simplest MVC example I could come up with.
In it, the servlet handles both the read and write operations.

The second, SimpleCommand, is exactly the same as SimpleMVC except the servlet actions are factored out to separate command objects.

The controller servlet does nothing more than read the form_action (requestParameter), map it to a command object, and call the command object's 'execute' method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!