Web Development with JavaServer Pages

Скачать в pdf «Web Development with JavaServer Pages»


Within the body of this method, several of the JavaMail method calls have the potential to throw exceptions. As we will see in the next section, for the current application within a JSP error page it is more convenient to pass these exceptions to callers of the sendEmail() method, rather than attempt to handle them locally. For this reason, sendEmail() is declared as throwing two exception classes, javax.mail .inter-net.AddressException and javax.mail.MessagingException.

15.2.4 The error page


These utility methods for collecting data and sending electronic mail can be combined in a JSP error page that serves both end users and developers. Here is the content of such a page, /webdev/error.jsp, where the method bodies have been removed for brevity’s sake:


<html>


<head>


<%@ page isErrorPage=,,true» %>


<%@ page import=»java.util.*, java.io.*» %>


<%@ page import=»javax.mail.*, javax.mail.internet.*» %>


<title>Oopsi</title>


</head>


<body bgcolor=»white»>


<P>


Sorry, an error has occurred:<br>


<center> <b><%= exception %></b> </center>


</p>


<% try {


String mailServer = «mail.taglib.com»;


String subject = «JSP Error Notification»;


String [] to = { «
webmaster@taglib.com» };


String from = «JSP Container <webmaster@taglib.com>»; sendEmail(mailServer, subject, to, from,


makeErrorReport(request, exception)); %>


<p>Not to worry, though! The guilty parties have been notified.</p>


<% }


catch (AddressException e) { %>


<p>Invalid e-mail address(es) for error notification.</p>


<% }


catch (MessagingException e) { %>


<p>Unable to send e-mail for error notification.</p>


<% } %>


</body>

Скачать в pdf «Web Development with JavaServer Pages»