JSP Tag Libraries

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


NOTE This solution breaks down if one of the page developers breaks the rules and uses the Writer/Outputstream exported by the implicit response object. This is one of the reasons you must not use these Writer/Outputstreams.


This JSP fragment demonstrates how the JSP runtime uses the writer stack and the out implicit variable:


<%@ taglib


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


<html>


<body>


<simp:BodyTag1> some text <simp:BodyTag2>


some other text </simp:BodyTag2 >


</simp:BodyTag1>


</body>


Figure 6.6 shows the values taken by out and the use of the writer stack at any given moment. In this figure there are five phases in the JSP execution. In the first phase (a) the JSP runtime is passing through the file and approaches the tag named BodyTag1. At this time, the output generated from the JSP execution goes to the original out variable (generated by the JSP runtime) and the writer stack is empty.


The next phase (b) occurs when the JSP runtime tackles BodyTag1 and starts to process its body. At this point, the JSP runtime creates a BodyContent (out1) to be used inside the body, pushes the original out on the writer stack, and sets out1 to be the current implicit out variable. From this moment forward, the JSP output goes into out1.


Phase (c) occurs when the JSP runtime tackles BodyTag2 and begins processing its body. The JSP runtime will create yet another BodyContent, out2, to be used inside the body, push out1 onto the writer stack (there are now two writers on the stack), and set out2 to be the current implicit out variable. Now the JSP output goes into out2.

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