Simulation Webform (5) in JSP

zhaozj2021-02-16  47

Simulation Webform (5) in JSP

There is also a problem that plagues us in step 4. According to the JSP specification, TAG's DostartTAG and DOENDTAG should output HTML text to the JSpwrite object instance OUT. If we really do this, 5, 6, how does it make sense to do TAG? Tag has been output into the OUT object, and the born is cooked, even if you call _Button.Setcaption in 5, 6: "Not my button"), the client will not see it. More importantly, the TAG's release method is called 4, and the attributes of tag have been unrecognizable in 5, 6 steps.

There is only one way, that is, in dostarttag, and doendtag do not output html text, do not release TAG resources in Release, and implement the three methods implemented in another approach, and be used in step 7 PageHandler calls.

There is another problem, there is a large number of non-dynamic texts in the JSP page, which are outputted by Out.print in the generated Java file, such as
Static text

button If you follow the above ideas, the final output would be: after
static text
button

This is because we didn't output HTML as scheduled, while the final output on the page, therefore, all TAG output will fall after all static contents. That is not a chaotic set.

Remember our previous written PageTag (see this article)? His parent class is Bodytagsupport, so that the implementation of him will also be like _Button1 (see this article). If the return value is not PageTag.doStartTag Tag.EVAL_BODY_INCLUDE, nor Tag.SKIP_BODY, the code will be executed as follows: out = pageContext.pushBody (); _PageTag.setBodyContent ((BodyContent) out); _PageTag.doInitBody ();

In this way, it is actually redirected the output of the JSP. PushBody's output is a real class of the Bodycontent class, and it is also a subclass of JSpWriter. Since then, any output of Out.print will not be truly written, and it is cached in the bodycontent. If you want to remove these strings in BodyContent, let them appear in the render method in the PageHandler as in the JSP page, we will get the correct page output.

We have said before, anything in the page is placed between and , all content in the page will not be output before pagetag.doendtag .

We write a class WebControl that inherits from BodyTagsupport, allowing other custom tags inherited from this class. The implementation of WebControl is as follows: public class webcontrol extends bodytagsupport {// block subclasses to override this method Final public int desartTAG () THROWS JSPEXCEPTION {IF (this control has a parent control, and the parent control is not pagetag is not formtag) {/ / Take the static html text before the start of this Tag, // .. placed in the render sequence of PageHandler to add itself to the control collection of the PageHandler} Else {// Before you get the TAG from BodyContent Static html text, // .. The render sequence placed in the parent control is // Add itself to the control collection of the parent control} // Clear the content in the BodyContent} // Blind Subcarrier to rewrite this method Final Public Int DoreTAG () throws jspexception {if (this control has a parent control, and the parent control is not pagetag nor for formtag) {// Static HTML text before the end of this TAG from BodyContent, // .. placed in the render sequence of PageHandler} Else {// Remove the static HTML text before the end of this TAG, // ..} //} // clear the content in the render sequence of the parent control} final void render () throws jspexception {startRender ();// Call the render () method of this control sub-control (executed by render sequence) Endrender (); Dispose ();} // The following three methods should be rewritten // Output control start tag (original DostartTag doing things) Protected void startRender () THROWS JSPEXCEPTION {} // Output control closure (originally made by doendtag) protected void endnder () throws jspexception {

} // Release the resources of the control (the thing you should do this) protected void dispose ()}}

At this point, according to the above ideas, it can be implemented in the JSP. There are still some problems running in RESIN, because RESIN is only instantified once, so it is necessary to modify the WebControl's DostartTAG method in RESIN. In this method, copy the this instance and add PageHandler or it. Parent controls.

(Continued ...) Related Articles:

Simulation Webform (1) in JSP

Simulation WebForm (2) in JSP in JSP Simulation Webform (3)

Simulation Webform (4) in JSP

转载请注明原文地址:https://www.9cbs.com/read-26775.html

New Post(0)