case study + mvc lec - 39. error pages by means of the page directive, a jsp can be given the...
TRANSCRIPT
Case Study + MVC
Lec - 39
Error Pages
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)
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.
Example Case StudyAddress Book
using Model-1 architecture
Address Bookingredients
• Database
Address Bookingredients
• JavaBeans– PersonInfo
• Has attributes– name– address– phoneNum
– PersonDAO• Encapsulate Database logic• Used to retrieve & save PersonInfo data
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
Address Book ingredients
• JavaServer Pages (cont.)
– Error Pages
• addbookerror.jsp
– Identifies the type of exception
– Displays the message associated with the received exception
Program Flow
addperson.jsp
saveperson.jsp
showperson.jsp
PersonInfo
PersonDAOJavaBeans
uses
uses
addbookerror.jspexception
searchperson.jsp
Lets put it all together
Netbeans project addressbookusingmodel1
Model View Controller Design Pattern
Model-View-ControllerDesign Pattern
• MVC separates
– Application data (contained in the model) from
– Graphical presentation components (the view) &
– Input/Event processing logic (the controller)
MVC in general
modelview
controller
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
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
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
MVC in summary
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)
MVC Model 1Architecture
MVC Model 1
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
MVC Model 2
Bean
JSP
JSP /Servlet
Controller
View
Model