JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»


<%@ page isErrorPage=»true» %>


<%@ taglib


uri=»http://www.manning.com/jsptagsbook/simple-taglib» prefix=»simp» %>


<html>


<head>


</head>


<body>


Sorry but your request was terminated due to errors:


<pre>


<simp:viewError/>


</pre>


<simp:log>


The following exception was thrown: <simp:viewError/> О </simp:log>


</body>


</html>

О Uses the error viewer to print the thrown exeption into the logger’s body This way the exception is reported into the servlet log.


In this example, we assume that the <simp:viewError> tag simply writes the current exception out to the page. Let’s review what happens during a request to this page and how our new tag is used. Note: we mention only the methods in this process that are important to this example; some life cycle calls have been omitted.


■    The page is requested and passed an exception from some other servlet or JSP.


■    The HTML at the top of the page is returned to the user.


■    Our <simp:log> tag is encountered and its body is processed.


■    The body is written to a BodyContent object, including the static message (“The following …”) and the result of the evaluation of <simp:viewError/>, which is just the text of the exception.


■    doAfterBody () is called, which is now handled at our base class. This, in turn, gets the BodyContent as a string and invokes processBody () on our subclass.


■    Our log method is called with the stringified BodyContent as its parameter— thereby logging the message and the exception text to the servlet log.

Скачать в pdf «JSP Tag Libraries»