Tag function: Write call tag to implement code reuse. To prevent users from accessing the tag page directly. Include can only be used for code reuse, but it does not prevent users from entering address access directly in the address bar.
Pros: 1. Implementing code Reuse
2. Separate data processing code and display code to facilitate Web application maintenance, and re-development
Save the tag file: Save under web-inf/tags/
Tag Tags:
Format one: <tag file name/>
Format two: <tag file name >
Marker body
</tag file name >
In the case of no marked body can only be used in format one, format two will be tagged body into the tag file, with <jsp:doBody/> to get this tag body.
Must be used before using the TAGLIB directive well-known tag library (that is, he called the tag file saved relative path)
Format: <%@ taglib tagdir= "relative path" prefix= "prefix"%>
Call format:< prefix: file name/>
Write the tag file:
Common directives: Tag, variable, include, attribute, taglib
Tag command:
Format: <% @tag Property 1 = "Property Value" Property 2 = "Property value"%>
Common Properties: Body-content
Property value: Empty (tag cannot be tagged body)
Tagdependent (tag can be labeled or without tag body)
Scriptless (tag can be tagged or without tag body) (default)
Language (same as the page Tag property in the JSP)
Import (same as the page Tag property in the JSP)
pageencoding Specifies the character encoding of the tag file, which defaults to "Iso-8859-1"
Include directive: (similar to the include directive in JSP)
Attribute directive: Allows JSP pages to pass the required data to the tag file
Format: <%@ attribute name= "Object name" required= "Ture" | " False "Type=" Object Type "%>
where name must have; required: if it is ture, it must be passed, if false, it can be passed, by default false;type is: java.lang.String type.
Use:
Format one:< prefix: Tag file name Object name = "Object reference"/>
Format two:< prefix: Tag filename Object name = "Object Reference" >
Marker body
</Prefix: Tag file name >
Variable directive: Can make JSP page dynamically pass data to the tag file.
Format:
<%@ variable name-given= "object name" variable-class= "Object Type" scope= "valid range"%>
where Name-given must have; Variable-class default is: java.lang.String type; Scope:at_begin (start with) at_nested (only used where tag tag) at_ End (use variable only after the JSP has ended)
The return of the object
Use Jspcontex.setattribute ("object's name", "object reference");
The study of tag in JSP