Custom label learning notes

xiaoxiao2021-03-06  87

2004-10-8 Thursday sunny

1. What is a custom label answer: 1) User-defined Java language elements, essentially running one or two interface JavaBean; 2) can connect with the JSP representation logic, and ordinary JavaBean The same business logic processing power; 2) When a JSP page is converted to servlet, the user-defined label between it is converted to an object called a label hander; 3) Operation of default objects, processing form data, access database, and others Corporate Services;

2. Features of the custom label library: 1) Customization by calling page transfer parameters; 2) Access all of the possible objects that are possible; 3) Modify the response of the call page generated; 4) Custom label can communicate with each other; 5) Complicated interaction can be achieved by label nested in the same JSP page.

3. How to Use Custom Label Answer: 1) Declaration Tag Library 2) Enable the label library to use the web application available

4. Declaration Tag Library A: 1) Use the Taglib Directive Declaration Tag Library 2) Syntax: <% @ Taglib URI = "URI" prefix = "pre"%> Note: a. URI attribute can be absolute, or it can be relative URL, the URL points to the tag library descriptor (TLD) file; b. URI attribute can also be a URL that does not exist, the URL is an absolute URL of the marker library descriptor (TLD) file in the web.xml file to local A map of the system; 3) Example: <% @ Taglib URI = "/ Web-inf / template.tld" prefix = "TEST"%> <% @ Taglib URI = "http://java.sun.com/jstl / core "prefix =" core "%>

5. Make the label library to perform Available: Method 1: Deploy tag handler classes under the web-inf / class directory; mode 2: Pack the tag handler class into a JAR file and placed in a web-inf / lib directory.

6. Several typical labels (Question: Can there be a label with the main body without attributes?) A: 1) Simple tag without attributes and main body: ; 2) Do not bring the main body but attribute Tags: ; 3) Tags with mains and properties: ... // label ; : A. Properties are listed in the Start Tag, which is specified in the Tag Library Descriptor (TLD) file, serving the custom behavior of the tag library; b. The tab is located between the Start Tag and End Tag, which can be any legal. JSP content or label;

7. Define the label: 1) Develop a Tag Handler; 2) Edit the tag library descriptor (TLD) file; 3) Establish an absolute URL of the tag library descriptor (TLD) file in web.xml One mapping (optional);

8. Tag Library Descriptor (TLD) file Answer: 1) A XML file describing the tag library; 2) The content begins to be a description of the entire library, then a description of TAG; 3) Tag library descriptor (TLD) file for Web Container confirms TAG and JSP page development tools; 9. Tag Handler Answer: 1) is some objects that are called to request custom tag values ​​during JSP page that references the tags; 2) One of Tag, SimpleTag and Bodytag must be implemented; 3) You can inherit one of Tagsupport and Bodytagsupport.

10. Inheritance relationship between the interface and class of the label library Answer: Performance form 1: a. Interface inheritance relationship: ☉ interface javax.servlet.jsp.tagext.jsptag ☉ Interface javax.servlet.jsp.tagext.simpletag Interface Javax. inheritance servlet.jsp.tagext.Tag ☉ interface javax.servlet.jsp.tagext.IterationTag ☉ interface javax.servlet.jsp.tagext.BodyTag b class:. ☉ class javax.servlet.jsp.tagext.TagSupport (implements javax .servlet.jsp.tagext.IterationTag, java.io.Serializable) ☉ class javax.servlet.jsp.tagext.BodyTagSupport (implements javax.servlet.jsp.tagext.BodyTag) ☉ class javax.servlet.jsp.tagext.SimpleTagSupport ( Implements javax.servlet.jsp.tagext.simpletAg) Performance forms 2: (Interface) JSptag ↑ | ˉˉˉˉˉˉˉˉ | (Interface) (Interface) Tag SimpleTAG ← --SIMPLETAGSUPPORT ↑ | (Interface) IterationTAG ← - Tagsupport ↑ ↑ | | (Interface) | Bodytag ← --Bodytagsupport

2004-10-9 Thursday

11. The method of processing a Tag class must implement the A: type tag handler method Simple doStartTag, doEndTag, release Attributes doStartTag, doEndTag, set / getAttribute ... release Body, No Itrative and doStartTag, doEndTag, release Evaluation Body, Itrative Evaluation DostartTag, DoaterTAG, DOENDTAG, Release Body, Interase, DONITTAG, DOENDTAG, Release, DoinitBody, DoeFterBody12. Simple Label Handling Program Way: 1) The dostartTag () and DOENDTAG () method of the TAG interface must be implemented; 2) Because there is no Body, the DostartTag () method must return Skip_body; 3) If the remaining page is to be executed, the doeendTag () method returns EVAL_PAGE, otherwise returns Skip_page; 4) For each tag properties, you must define a feature in the label handler class and get And SET methods to convent the JavaBeans system

13. Custom Label Answer with Body: 1) The dostartTAG () and DOEENDTAG () method of the TAG interface must be implemented; 2) DOAFTERBODY () method of the ITERATIONTAG interface can be implemented; 3) DoinitBody and setBodyContent methods for the bodyTAG interface; 4) The DOSTARTTAG method can return Skip_Body, Eval_BODY_INCLUDE, or EVAL_BODY_BUFFERED (when you want to use bodycontent); 5) DoendTAG method can return skip_page or eval_page; 6) DoafterBody method can return Eval_Body_again, Skip_body;

14. Define the label of the script variable A: 1) Define two steps to define the script tag: a. Listed script variables in the tag library descriptor (TLD) file; b. Define tag extended information classes ( TEI) and in the TLD file include this type element (TEI-Class); 2) Variables must be set in the label processing program class; 3) Label Extension Information Class (TEI) must inherit TageXTraInfo and overwritten GetVariableInfo () method; 4) The range of variables may be one of AT_BEGIN, NESTED, AT_END (Tag Extension Information Class (TEI) "defined in VariableInfo;

15. Validity of scripting variables Answer: Variable | Validity ----------------------------------- - NESTED | The parameter in the tag is a valid at_begin | tag between STARTTAG to EndTAG, the parameter in the label starts to the JSP page. It is a valid AT_END | Tag parameter in the label. The end of the label is valid. of

2004-10-10 Thursday sunny

16. TAG interface method A: Interface javax.servlet.jsp.tagext.tag ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------- EVAL_BODY_INCLUDE: INT EVAL_PAGE: INT SKIP_BODY: INT SKIP_PAGE: INT ------------ ------------------------------------------ Release (): void getparent (): javax.servlet.jsp.tagext.tag setParent (javax.servlet.jsp.tagext.tag): void doendtag (): int dostartTag (): int setPageContext (javax.servlet.jsp.pageContext) : Void17. Tag lifecycle Answer: 1) setPageContext (javax.servlet.jsp.pagecontext): void 2) setparent (javax.servlet.jsp.tagext.tag): void 3) // setttribute: void 4) dostarttag : INT 5) DOENDTAG (): INT 6) Release (): void

18. The relationship between the bodytag and the tag interface: Interface javax.servlet.jsp.tagext.bodytag -> interface javax.servlet.jsp.tagext.tag ----------------- ----------------------------------------------- --------------------- DOINITBODY (): void setbodycontent (javax.servlet.jsp.tagext.bodyContext): Void DOAFTERBODY (): int

19. BodyTag's processing Answer: 1) setPageContext (javax.servlet.jsp.pagecontext): void 2) setParent (javax.servlet.jsp.tagext.tag): void 3) // setParent () DOSTARTTAG () : INT 5) SetBodyContent (javax.servlet.jsp.tagext.bodycontent): Void 6) DOINITBODY (): Void 7) DoafterBody (): int doendtag (): int 9) release (): void

20. SimpleTAG interface method A: javax.servlet.jsp.tagext.simpletag --------------------------------- -------- Dotag (): void getParent (): jspfragment jspbody: Void setjspContext (jspContext PC): Void setParent (jsptag parent): Void

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

New Post(0)