aspose file tools*
The moose likes Servlets and the fly likes MVC Architecture Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "MVC Architecture" Watch "MVC Architecture" New topic
Author

MVC Architecture

Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

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.


PANKAJ SHET
B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 225

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Sep 08, 2006
Posts: 225

Hi Ben sir,
Which are those rare cases?and why do we use it in them?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: MVC Architecture