• 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

MVC Architecture

 
Ranch Hand
Posts: 338
Scala Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I am confused between the High level response-request architecture,and MVC architecture.

I use HFSJ book.

In that book, the second chapter shows the request-response cycle.
it says that:-

1. The user enters the servlet request.
2. Request goes to Web Container.
3. Web Container creates the Request and Response objects.
4. Web container finds the correct servlet based on the URL.
5. On finding the correct servlet, it creates the thread for that servlet.
6. Web Container puts the user request in the request object and passes the object to the thread.
7. Servlet thread then calls the service() method.
8. On the service method in turn, calls the doGet()or doPost() method depending on the GET or POST request.
9. doGet()or doPost() then will dynamically generate the response page.
10. This response page will then be put into the Response Object.
11. Web Container then will convert this response object into HttpResponse.
12. This HttpResponse is then sent to then client.
13. Web Container the destroys the request and response objects.

MVC architecture Eg.on Page 71 says that:-

1. The client makes a request for form.html
2. The Container retrieves the form.html page.
3. The Container returns the page to the browser.
4. The user answers the questions on the form and sends the request data to the container.
5. Web container finds the correct servlet based on the URL and passes the request to the servlet.
6. The Servlet then calls the BeerExpert Component for help.
7. The expert class returns an answer,which the servlet adds to the request object.
8. The servlet forwards the request to the JSP.
9. The JSP gets the answer from the request object.
10.The JSP generates the page for the container.
11.The Container returns the page to the user.

The questions are:-
1.When or in what situations,do we use either of the architecture?
2.In,MVC architecture,from where did the BeerExpert Component and Result.jsp come from?
3.After comparing these 2 architectures,
(i) On finding the correct servlet,
(a)It creates the thread for that servlet. Web Container puts the user request in the request object and passes the object to the thread.
(b)The Servlet then calls the BeerExpert Component for help.

Just explain me the complete scenerio.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These aren't two opposing architectures.

MVC is built on top of the request, response architecture.
In other words, all of the steps from the first list will still occur when using MVC.

The only difference is that, in step 9 (fist list) the servlet doesn't generate the output by itself. Rather, it (the controller) makes calls to your business objects (model) and then forwards to a JSP (view) where the markup is generated.

Everything then picks up at step 10.
 
Pankaj Shet
Ranch Hand
Posts: 338
Scala Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I got the answer but when do we use ,that is,in what situation do we use either of the architectures?
When is the respone page dynamically generated and when do we use business objects and jsp?
Where does that business object come from?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, it's not an either/or situation.
You're always using the first.
Except for a few rare cases, I always use the second as well.

The first is an explanation of how a servlet container works.
The second is a description of MVC which is considered by most to be the best way to structure your server side code.
 
Pankaj Shet
Ranch Hand
Posts: 338
Scala Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben sir,
Which are those rare cases?and why do we use it in them?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would not use MVC if the result being returned to the client was not an HTML web page.

Examples:
  • Streaming a binary file to the browser
  • Returning a JSON or XML to a webservice client or AJAX call.


  • Anytime
     
    So I left, I came home, and I ate some pie. And then I read this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic