case study + mvc lec - 39. error pages by means of the page directive, a jsp can be given the...

23
Case Study + MVC Lec - 39

Upload: betty-harrell

Post on 31-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Case Study + MVC

Lec - 39

Page 2: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Error Pages

Page 3: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Error Pages

• By means of the page directive, a JSP can be given the responsibility of an Error page

• An Error JSP will be called by the Web Server when an uncaught exception gets generated

• The exception is passed as an instance of java.lang.Throwable to the Error JSP (accessible via implicit exception object)

Page 4: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Defining & UsingError Pages

• isErrorPage attribute of page directive is used to declare a JSP as an error page.

• JSP pages are informed about the error page by setting errorPage attribute of page directive.

Page 5: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Example Case StudyAddress Book

using Model-1 architecture

Page 6: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Address Bookingredients

• Database

Page 7: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Address Bookingredients

• JavaBeans– PersonInfo

• Has attributes– name– address– phoneNum

– PersonDAO• Encapsulate Database logic• Used to retrieve & save PersonInfo data

Page 8: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Address Bookingredients

• JavaServer Pages– addperson.jsp

• Used to collect new person info

– saveperson.jsp• Receives person info from addperson.jsp• Saves it into database

– searchperson.jsp • Used to provide search criteria to search Person’s info, based

on name

– showperson.jsp• Receives person name, to be searched in database• Retrieves & display person records against that person name

Page 9: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Address Book ingredients

• JavaServer Pages (cont.)

– Error Pages

• addbookerror.jsp

– Identifies the type of exception

– Displays the message associated with the received exception

Page 10: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Program Flow

addperson.jsp

saveperson.jsp

showperson.jsp

PersonInfo

PersonDAOJavaBeans

uses

uses

addbookerror.jspexception

searchperson.jsp

Page 11: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Lets put it all together

Netbeans project addressbookusingmodel1

Page 12: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Model View Controller Design Pattern

Page 13: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Model-View-ControllerDesign Pattern

• MVC separates

– Application data (contained in the model) from

– Graphical presentation components (the view) &

– Input/Event processing logic (the controller)

Page 14: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC in general

modelview

controller

Page 15: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC in general: model

modelview

controller

• Represents the state of the component (ie its data and the methods required to manipulate it)

• Independent of how the component is viewed or rendered

Page 16: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC in general: view

modelview

controller• Appearance of the

component

• Can be multiple views for the same model within a single applications

• Model may have different views in different applications or operating systems

Page 17: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC in general: controller

modelview

controller

• Dictates how a component interacts with events

• Sends events of interest to the model so that it can update itself

Page 18: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC in summary

Page 19: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

Evolution of MVC Architecture

• No MVC

2. MVC Model 1

3. MVC Model 2

4. Web application framework (based on MVC model2)– Struts, Sun ONE application framework

5. Web application framework– JavaServer Faces (JSF)

Page 20: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC Model 1Architecture

Page 21: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC Model 1

Page 22: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC Model 1 – A Detailed Story

ClientClient

JSP Engine & Web Server

JSP Engine & Web Server

request

JSPFileJSPFile

request

request Call for component

Component(JavaBean or EJB)

Component(JavaBean or EJB)

responseData

response

response

CompiledServlet

Page 23: Case Study + MVC Lec - 39. Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called

MVC Model 2

Bean

JSP

JSP /Servlet

Controller

View

Model