Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Lecture 39 43

Lecture 39 43

Ratings: (0)|Views: 54 |Likes:
Published by api-3729920

More info:

Published by: api-3729920 on Oct 15, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Web Design & Development
492
Lecture 39
MVC + Case Study

We have covered an adequate amount of Servlets and JSPs in detail. Now, the time has come to learn different architectures that are most commonly used for the sake of web development. These architectures also help us to understand where these components best fit in. In this handout, we\u2019ll cover the most widely used/popular architecture i.e.Model

View Controller (MVC).

A small case study \u201cAddress Book\u201d is also part of this handout that is based on MVC Model 1. Before moving on to MVC, let\u2019s see what error pages are and how they are used?

Error Page

Error Pages enables you to customize error messages. You can even hide them from the user's view entirely, if you want. This also makes possible to maintain a consistent look and feel throughout an application, even when those dreaded error messages are thrown.

By means of page directive, a JSP can be given the responsibility of an Error page. An Error JSP is called by the web server when an uncaught exception gets occurred. This exception is passed as an instance ofjava.lang.Throwable to Error JSP (also accessible via implicitexception object).

Defining and Using Error Pages
\ue000 i s E rr o rP a ge attribute of a page directive is used to declare a JSP as an error
page.
\ue000JSP pages are informed about the error page by settingerrorPage attribute of
page directive

In the figure below,error.jsp is defined as JSP Error page andindex.jsp is informed to callerror.jsp if any uncaught exception rose. This is done by setting attributeserr o rP a ge andisErrorPage of the page directive on these JSPs.

index.jsp
error.jsp
<%@ page \u2026
erroPage=\u201cerror.jsp\u201d%>
\u2026.
\u2026.
<%@ page \u2026isErroPage=\u201ctrue\u201d%>
\u2026.
\u2026.
exception
Web Design & Development
-4 9 3 -
Case Study \u2013 Address Book

What we have learned is going to be implemented in this Address Book example. Here MS-Access is being used as DBMS. This database will have only one table,Person with following attributes

Ingredients of Address Book
Java Beans, Java Server Pages and Error Page that are being used in this Address Book
example are: -
\ue000Java Beans
\ue001 P e rs o nI n f o\u2013Has following attributes:

\u2013 name
\u2013 address
\u2013 phoneNum

\ue001 P e rs o nD A O
\u2013 Encapsulates database logic.
\u2013 Therefore, it will be used to save and retrieve PersonInfo data.
\ue000 Java Server Pages
\ue001 a d dp e rs o n .j s p
\u2013 Used to collect new person info that will be saved in database.
\ue001 s a ve p er s o n. j sp
\u2013 Receives person info from addperson.jsp
\u2013 Saves it to database
\ue001 s e ar c hp e r so n .j s p
\u2013 Used to provide search criteria to search Person\u2019s info by providing name
Web Design & Development
-4 9 4 -
\ue001 s h ow p er s o n. j sp
\u2013 This page receive person\u2019s name fromsearc hperson.jsp to search in
database
\u2013 Retrieves and displays person record found against person name
\ue000Error Page
\ue001 a d db o ok e r ro r .j s p
\u2013 This page is declared as an error page and used to identify the type of
exception.
\u2013 In addition to that, it also displays the message associated with the received
exception to the user.
Program Flow

Now let\u2019s discuss the flow of program. Assume that the system has been deployed on a JSP compatible Web Server like Tomcat and has been ready to use for clients. The following figure helps to understand the program flow of this small example.

addperson.jsptakes person\u2019s information from the user and sends it to saveperson.jsp. After receiving request, saveperson.jspmakes an object of PersonInfousing received information and saves it into the database using PersonDAO Java bean.

Similarly,searchperson.jsp takes search criteria (name) from the user and passes it toshowperson.jsp that searches the record in database usingPersonDAO and shows the results to the user.

If any uncaught exception is generated on these JSP,addb ookerror.jsp is called implicitly, which displays an appropriate message to the user after identifying the exception type.

addperson
.jsp
saveperson
.jsp
showperson
.jsp
PersonInfo
PersonDAO
JavaBeans
uses
uses
excenption
searchperson
.jsp
addbookerror
.jsp

Activity (4)

You've already reviewed this. Edit your review.
1 hundred reads
ALi liked this
ALi liked this
Omer Ali liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->