This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

how one service() handles different requests???

 
Ranch Hand
Posts: 3850
  • 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 ]
 
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: 3850
  • 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.
 
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: 3850
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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.
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic