Understanding the need for MVC MVC Frameworks MVC

  • Slides: 8
Download presentation
Understanding the need for MVC

Understanding the need for MVC

MVC Frameworks

MVC Frameworks

MVC Architecture

MVC Architecture

MVC Architecture The term “Architecture” suggests “overall system design”. It is quite common for

MVC Architecture The term “Architecture” suggests “overall system design”. It is quite common for applications to handle some requests with servlets. The other requests with JSP and servlets acting in conjunction. Due to this, we have to use the MVC approach.

Implementing MVC with Request. Dispatcher The most important point about MVC is the idea

Implementing MVC with Request. Dispatcher The most important point about MVC is the idea of separating the business logic and data access layers from the presentation layer. 1) 2) 3) 4) 5) 6) Define bean to represent data Use a servlet to handle requests Populate the Beans Store the bean in the request, session, or servlet Forward request to JSP Extract data from the Bean

Summarizing MVC Code This section Summarizes the code that would be used for request-based,

Summarizing MVC Code This section Summarizes the code that would be used for request-based, session-based and application-based MVC approaches 1) Request-Based Data Sharing 2) In request-based sharing the servlets stores the beans in the Http. Servlet-Request, where they are accessible only to the destination JSP pages. 3) Servlet: 4) 5) 6) Request. set. Attribute(“Key”, Value); Request. Dispatcher request. get. Request. Dispatcher(“page. jsp”); Dispatcher. forward(request, response) 7) 8) 9) JSP Page: <jsp: use. Bean id=“key” type=“class” scope=“request” /> <jsp: get. Property name=“key” Property=“xyz” /> d=new

Summarizing MVC Code 2) Session Based Data Sharing In this the servlet stores the

Summarizing MVC Code 2) Session Based Data Sharing In this the servlet stores the beans in the Http. Session, where they are accessible to the same client in the destination JSP Page. Servlet: Session. set. Attribute(“Key”, Value); 1. 2. Request. Dispatcher request. get. Request. Dispatcher(“page. jsp”); Dispatcher. forward(request, response) d=new 3. JSP Page: 4. 5. <jsp: use. Bean id=“key” type=“class” scope=“Session” /> <jsp: get. Property name=“key” Property=“xyz” />

Summarizing MVC Code 3) Application Based Data Sharing In this the servlet stores the

Summarizing MVC Code 3) Application Based Data Sharing In this the servlet stores the beans in the Servlet-Context, where they are accessible to any client in the destination JSP Page. Servlet: get. Servlet. Context(). set. Attribute(“Key”, Value); 1. 2. Request. Dispatcher request. get. Request. Dispatcher(“page. jsp”); Dispatcher. forward(request, response) 3. JSP Page: 4. <jsp: use. Bean id=“key” type=“class” scope=“Application” /> <jsp: get. Property name=“key” Property=“xyz” /> 5. d=new