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
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 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).
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.
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
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.
Now bringing you back...
Does that email address look wrong? Try again with a different email.