Model View Controller�MVC Architechture
Amity School of Engineering & Technology
�Need for MVC
Servlets are great when your application requires a lot of real programming to accomplish its task. As we know, servlets can manipulate HTTP status codes and headers, use cookies, track sessions, save information between requests, compress pages, access databases, perform many other tasks flexibly and efficiently. But, generating HTML with servlets can be tedious and can yield a result that is hard to modify.
Amity School of Engineering & Technology
Need Of MVC contd..
That’s where JSP comes in: JSP lets you separate
much of the presentation from the dynamic content. That way, you can write the HTML in the normal manner, even using HTML-specific tools and putting your Web content developers to work on your JSP documents. JSP expressions, scriptlets, and declarations let you insert simple Java code into the servlet that results from the JSP page, and directives let you control the overall layout of the page.
3
Amity School of Engineering & Technology
Need Of MVC contd…
The assumption behind a JSP document is that it provides a single overall presentation.
Servlet is good in writing business logics .
JSP is good in data presentation.
The solution is to use both servlets and JSP. This approach, known as the Model View Controller (MVC) or Model 2 architecture. The original request is handled by a servlet.
4
Amity School of Engineering & Technology
Need Of MVC contd…
The servlet invokes the business-logic and data-access code and creates beans to represent the results (that’s the model). Then, the servlet decides which JSP page is appropriate to present those particular results and forwards the request there (the JSP page is the view).
5
Amity School of Engineering & Technology
MVC Architecture :
The most important point about MVC is the idea of separating the business logic and data access layers from the presentation layer.
6
Amity School of Engineering & Technology
Implementing MVC
Steps required for implementing MVC:
7
Amity School of Engineering & Technology
THE END
8
Amity School of Engineering & Technology