Thursday
1. What is a custom tag?
Answer: 1) the User-Defined Java language element is essentially a JavaBean that runs one or two interfaces;
2) It can be very confidential to be associated with the JSP representation logic, and has the same business logic processing capability as normal JavaBean;
2) When a JSP page is changed to a servlet, the User-Defined tag in the process is converted to an object called the tag hander;
3) You can operate on default objects, process form data, access databases, and other enterprise services;
2. Features of the custom tag Library
Answer: 1) Call the page to PASS Parameters for customization;
2) access all possible JSP page objects;
3) modify the response generated on the call page;
4) custom tags can communicate with each other;
5) You can use tag nesting on the same JSP page to implement complex interaction.
3. How to Use the custom tag Library
Answer: 1) Declare the tag Library
2) Make tag library execution available to Web Applications
4. Declare the tag Library
Answer: 1) Use the taglib command to declare the tag Library
2) Syntax: <% @ taglib uri = "Uri" prefix = "pre" %>
Note: The a. Uri attribute can be absolute or relative URL. The URL points to the tag library Descriptor (TLD) file;
B. The URI attribute can also be a non-existent URL, which is a ing of the absolute URL of the library Descriptor (TLD) file to the local system in the web. xml file;
3) Example: <% @ taglib uri = "/WEB-INF/template. TLD" prefix = "test" %>
<% @ Taglib uri = "http://java.sun.com/jstl/core" prefix = "core" %>
5. Make tag library execution available
A: Method 1: deploy the tag handler class under the WEB-INF/classes directory;
Method 2: Package the markup handler class into a jar file and place it in the WEB-INF/lib directory.
6. Several Typical tags (question: can there be tags with subject but no attribute ?)
Answer: 1) simple tag without attributes and subject: <mytaglibs: sometag/>;
2) labels without subject but attributes: <mytaglibs: sometag user = "tonydeng"/>;
3) labels with subject and attribute: <mytaglibs: sometag user = "tonydeng">
... // TAG body
</Mytaglibs: sometag>;
Note: A. attributes are listed in the start tag, which is specified in the tag library Descriptor (TLD) file to serve the tag library's custom behavior;
B. the TAG body is located between the start tag and the end tag. It can be any legal JSP content or tag;
7. Define tags
Answer: 1) Develop and implement tag classes (TAG handler );
2) edit the tag library Descriptor (TLD) file;
3) create a ing for the absolute URL of the tag library Descriptor (TLD) file in Web. XML (this step is optional );
8. Mark the library Descriptor (TLD) File
A: 1) an XML file describing the tag library;
2) The content begins with the description of the entire library, followed by the description of the tag;
3) The tag library Descriptor (TLD) file is used for Web container to confirm the tag and JSP page development tools;
9. Tag Handler)
Answer: 1) Some objects called by web iner during execution of JSP pages that reference tags for custom tag values;
2) tags must be implemented, one of simpletag and bodytag;
3) You can inherit one of tagsupport and bodytagsupport.
10. Interface and class inheritance relationship of the tag Library
Answer: Form 1:
A. interface inheritance relationship:
☉Interface javax. servlet. jsp. tagext. jsptag
☉Interface javax. servlet. jsp. tagext. simpletag
☉Interface javax. servlet. jsp. tagext. Tag
☉Interface javax. servlet. jsp. tagext. iterationtag
☉Interface javax. servlet. jsp. tagext. bodytag
B. Inheritance relationships of classes:
☉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)
Form 2:
(Interface)
Jsptag
Bytes
| Too many requests have been sent too many requests |
(Interface)
Tag simpletag tags -- simpletagsupport
Bytes
|
(Interface)
Iterationtag tags -- tagsupport
Zookeeper
|
(Interface) |
Bodytag tags -- bodytagsupport
Thursday
11. methods required for a tag handler class
Answer: Method of tag handler type
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, InterAction dostarttag, doendtag, release, doinitbody, doafterbody
12. Simple tag handler class
Answer: 1) The dostarttag () and doendtag () Methods of the tag interface must be implemented;
2) because no body exists, the dostarttag () method must return the skip_body;
3) if other pages are to be executed, the doendtag () method returns eval_page; otherwise, skip_page is returned;
4) for each tag attribute, you must define a feature in the tag handler class and the get and set methods to be consistent with the Javanese system practices.
13. custom tag with body
Answer: 1) The dostarttag () and doendtag () Methods of the tag interface must be implemented;
2) doafterbody () method that implements the iterationtag interface;
3) The doinitbody and setbodycontent methods of the bodytag interface can be implemented;
4) The dostarttag method can return skip_body, eval_body_include, or eval_body_buffered (when you want to use bodycontent );
5) The doendtag method can return skip_page or eval_page;
6) The doafterbody method can return eval_body_again and skip_body;
14. Define the tag of the script variable (iterative tag Library)
Answer: 1) perform the following two steps to define the script Tag:
A. List script variables in the tag library Descriptor (TLD) file;
B. Define the tag Extension Information Class (TEI) and include this class Element (TEI-class) in the TLD file );
2) variables must be set using the pagecontext. setattribute () method in the tag handler class;
3) The tag Extension Information Class (TEI) must inherit tagextrainfo and overwrite the getvariableinfo () method;
4) The variable range can be at_begin, nested, or at_end (defined in variableinfo of the tag Extension Information Class (TEI;
15. Validity of script variables
Answer: Variable | Validity
---------------------------------------
Nested | the parameters in the tag are valid between starttag and endtag.
At_begin | the parameters in the tag are valid from the start of the tag to the end of the JSP page.
At_end | the parameters in the tag are valid from the tag end to the JSP page end.
Thursday
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): void
17. Tag Lifecycle
Answer: 1) setpagecontext (javax. servlet. jsp. pagecontext): void
2) setparent (javax. servlet. jsp. tagext. Tag): void
3) // setattribute: void
4) dostarttag (): int
5) doendtag (): int
6) release (): void
18. Relationship between bodytag and tag Interface
A: interface javax. servlet. jsp. tagext. bodytag --> interface javax. servlet. jsp. tagext. Tag
------------------------------------------
+ Eval_body_again: int
------------------------------------------
+ Doinitbody (): void
+ Setbodycontent (javax. servlet. jsp. tagext. bodycontext): void
+ Doafterbody (): int
19. bodytag processing process
Answer: 1) setpagecontext (javax. servlet. jsp. pagecontext): void
2) setparent (javax. servlet. jsp. tagext. Tag): void
3) // setparent ()
4) 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 (): jsptag
+ Setjspbody (jspfragment jspbody): void
+ Setjspcontext (jspcontext PC): void
+ Setparent (jsptag parent): void
21. Life Cycle of the simpletage Interface
Answer: 1) New:
Every time a tag is encountered, the container constructs a simpletag instance. This constructor has no parameters. Like the redbooks tag, simpletag cannot be buffered, so it cannot be reused. A new instance needs to be constructed each time.
2) setjspcontext () and setparent (): The setparent () method is called only when the tag is within another tag;
3) set attributes: Call the setter method of each attribute;
4) setjspbody ();
5) dotag (): the logic, iteration, and Body Calculation of all tags are in this method;
6) Return