Struts tag Library

Source: Internet
Author: User
Tags http cookie tld
Schensheng913 [original]

The struts tag library used by the JSP window component consists of four types of tags:
2. Bean Tag: used to manage beans on JSP pages
3. Logic Tag: used to control the process on the JSP page
4. HTML Tag: used to generate HTML tags, display data in the form, and use the session ID to program the URL
5. template Tag: Use a dynamic template to construct pages in normal format
2.1 bean tag
This tag library contains tags used to define new beans, access beans, and their attributes. The Struts Framework provides multiple custom tags for processing JavaBean on JSP pages. These tags are encapsulated in a common tag library that defines its tag library descriptor in the file struts-bean.tld. The bean tag library defines the tag in four subcategories:
Create and copy bean tags
Script variable definition mark
Bean translation tag
Message internationalization mark
2.1.1 bean copy tag
You can define new beans, copy existing beans, and copy attributes from existing beans.
<Bean: Define> flag is used:
Define new string constants
Copy existing bean to the newly defined bean object
Copy the attributes of an existing bean to create a new bean.
<Bean: Define> tag attributes:
Attribute description ID: the name of the newly defined bean script variable. You must set the class value of the type definition that introduces the script variable to assign the name of the target bean of a new object name to the script variable defined in the ID property. If the value attribute is not set, you must set the attribute name of the bean defined by the property name attribute to define the new bean.
13
Scope scope of the source bean. If not set, the search scope is from the page scope to the scope of the application scope toscope target bean. If not set, the default value is page scope.
For example, define a bean:
<Bean: Define id = "test" value = "this is a test"/>
The source bean is copied in the page scope. Another bean in the request scope:
<Bean: Define id = "targetbean" name = "sourcebean"
Scope = "page" toscope = "request"/>
2.1.2 marking of defining script variables
Define and generate script variables from multiple resources, including cookies, request parameters, and HTTP headers. The attributes are as follows:
Property description ID script variable and name of the page scope attribute to be defined Cookie/Header/parameter name multiple if this property sets any value, all matching cookies are accumulated and stored in a cookie [] (an array) type bean. If no value is set, the first value of the specified cookie is used as the value of the cookie type. If no matching cookie or value exists, the default value specified for this attribute is returned.
For example:
<Bean: Cookie id = "mycookie" name = "username"/>
The script variable name is mycookie, And the cookie name used to create this attribute is username.
<Bean: Header id = "myheader" name = "Accept-language"/>
The script variable name is myheader, And the request header name is accept-language.
<Bean: parameter id = "myparameter" name = "myparameter">
The script variable name is mypatameter, and the name of the stored request parameter is also myparameter.
<Bean: Include> the tag retrieves the response of a resource and introduces a script variable and a page scope attribute of the string type. This resource can be a page, an actionforward, or an external URL. Unlike <JSP: Include>, the resource response is stored in a page-scoped bean rather than written to the output stream. The attributes are as follows:
Property description ID script variable and name of the page scope attribute to be defined page an internal resource forward an actionforward href complete URL of the resource to be included
For example:
<Bean: Include id = "myinclude" page = "myjsp? X = 1 "/>
The name of the script variable is myinclude. The response to be retrieved comes from the resource myjsp? X = 1.
<Bean: Resource> the tag retrieves resources in a web application and introduces a script variable and page scope attribute of inputstream or string type. If a problem occurs during resource retrieval, a request time exception occurs. The attributes are as follows:
Attribute description
14
Id script variable and name of the page scope attribute to be defined the relative path of the resource input if this attribute does not exist, the resource type is a string
For example:
<Bean: Resource id = "myresource" name = "/WEB-INF/images/myresource. xml"/>
The name of the script variable is myresource, and the name of the resource to be retrieved is myresource. xml.
2.1.3 display bean attributes
The tag library defines the <Bean: Write> tag to send bean attributes to the encapsulated JSP page writer. This tag is similar to <JSP: getproperty> and has the following attributes:
Attribute description name: name of the bean to be displayed. The name of the property to be displayed. If this property class has Java. beans. propertyeditor, getastext () or tostring method will be called scope bean scope, if not set, search range is from page to Application Scope filter if set to true, all special HTML characters in the property will be converted to the corresponding entity reference ignore. If it is set to false, a request time exception is generated when the property is found; otherwise, null is returned.
For example:
<Bean: write name = "mybean" property = "myproperty" Scope = "request"
Filter = "true"/>
Mybean properties myproperty will be displayed, with a request scope. If any special HTML characters are found, they will be converted to corresponding entity references.
2.1.4 message tagging and Internationalization
The strtus framework supports internationalization and localization. Users define their own region on their computers. When a web application needs to output a message, it will reference a resource file, all messages in this file use the appropriate language. An application may provide many resource files, each of which provides messages written in different languages. If the resource file of the selected language is not found, the default resource file will be used.
The Struts Framework supports internationalization by using the <Bean: Message> flag and the locale and resourcebundle classes defined in Java. util data packets. Java. Text. messageformat supports message formats. With this feature, developers can internationalize and Set message formats without having to understand the details of these classes.
Use strtus for internationalization and Localization:
The first step is to define the name of the resource file, which will contain all messages written in the default language in the program. These messages are stored as "keyword-value", as follows:
Error. validation. Location = the entered location is invalid
This file needs to be stored in the class path, and its path must be transmitted to actionservlet as an initialization parameter. The path format must comply with the standard naming rules of the complete Java class. For example, if the resource file is stored in the WEB-INF/classes directory, the file name is
15
Applicationresources. properties, the parameter value to be passed is applicationresources. If the file is in the WEB-INF/classes/COM/test, the parameter value should be com. Test. applicationresources.
All resource files must be stored in the directory where the basic resource files are located to be internationalized. The basic resource file contains messages written in the default region language-local language. If the name of the basic resource file is applicationresources. properties, the name of the resource file written in other specific languages should be applicationresources_xx.properties (XX is ISO encoded, for example, en ). Therefore, these files should contain the same keywords, but the value of the keywords is written in a specific language.
The region initialization parameter of actionservlet must be transmitted with a true value, so that actionservlet stores a region object for a specific user's computer under the action. locale_key keyword in the user session. Now you can run an international web site, which can be automatically displayed in the corresponding language according to the region set on your computer.
We can also use a specific string to replace some messages, just like using Java. Text. messageformat:
Error. invalid. Number = The number {0} is valid
We can replace the string {0} with any number we need. <Bean: Message> the tag attributes are as follows:
Attribute description the attribute name of the region object stored in the locale user session defined in the key resource file. If this parameter is not set, the default value is action. locale_key bundle in the application context, which stores the attribute name of the resource object. If this attribute is not set, the default value is action. message_key arg0. The first replacement parameter value arg1. The second replacement parameter value arg2. The third replacement parameter value arg3. The fourth replacement parameter value
For example, a message is defined in the resource file:
Info. mykey = the numbers entered are {0}, {1}, {2}, {3}
We can use the following message tag:
<Bean: Message key = "info. mykey" arg0 = "5" arg1 = "6" arg2 = "7" arg3 = "8"/>
This information is marked as: The numbers entered are 5, 6, 7, 8
2.2 logical tag
The logic library tag can be used to process the appearance logic without using scriptlet. The tags contained in the struts logical tag library can generate output text with conditions, and generate output text repeatedly in the object collection, as well as application process control. It also provides a set of tags for processing process control in JSP pages. These tags are encapsulated in a tag package whose file name is struts-logic.tld. The tag defined by the logical tag library can perform the following three functions:
Conditional Logic
Repeated
Forward/redirect response
16
2.2.1 conditional Logic
Struts has three types of conditional logic. The first type can compare the sizes of the following entities with a constant:
Cookie
Request Parameters
Bean or bean Parameters
Request Header
The tags are listed below:
Tag function <equal> returns true if the constant is equal to the defined entity. <notequal> If the constant is not the same as the defined entity, returns true <greaterequal> If the constant is greater than or equal to the defined entity, returns true <lessequal> If the constant is less than or equal to the defined entity, returns true <lessthan> If the constant is smaller than the defined entity, returns true <greaterthan> If the constant is greater than the defined entity, returns true.
All tags in this category have the same attributes.
Attribute description value to be compared constant value cookie to be compared HTTP cookie name header to be compared HTTP request header name parameter to be compared HTTP request parameter name if the bean or bean attributes are to be compared, this attribute indicates the scope bean of the bean attribute whose name property to be compared. If no scope is specified, its search range is from page to application.
For example:
<Logic: Equal Parameter = "name" value = "somename">
The entered name is somename
</Logic: equal>
Determine whether the value of the request parameter named "name" is "somename ".
<Logic: greaterthan name = "Bean" property = "prop" Scope = "page" value = "7">
The value of bean. Prop is greater than 7
</Logic: greaterthan>
Determine whether there is a bean named "Bean" in the page scope. It has a prop attribute and whether the value of this attribute is greater than 7. If this attribute can be converted to a value, the value is compared; otherwise, the string is compared.
The second type of condition tag defines two tags:
<Logic: Present>
<Logic: notpresent>
Their function is to determine whether a specific project exists before calculating the TAG body. The marked attributes and attribute values determine the items to be checked.
Attribute description
17
Cookie the cookie specified by this attribute will be checked for existence of header the request header specified by this attribute will be checked for existence of parameter the request parameter specified by this attribute will be checked for existence of name if property property is not set, the bean with this attribute is checked for existence. If this parameter is set, the bean and bean attributes are checked for existence. Property checks whether the specified attribute scope exists in the bean with the name attribute. If the bean name is specified, this is the bean scope. If no scope is specified, the search scope ranges from page to application scope. Role check whether the currently confirmed user belongs to a special role user check whether the currently confirmed user has a specific name
For example:
<Logic: notpresent name = "bean" property = "prop" scope = "page">
The bean property bean. Prop is present
</Logic: notpresent>
Tag to determine whether a bean named "Bean" exists in the page scope. This bean has a prop attribute.
The third type of condition tags are complex. These tags check the content of the TAG body based on the template matching results. In other words, these tags determine whether the value of a specified project is a substring of a specific constant:
<Logic: Match>
<Logic: notmatch>
These tags allow the JSP Engine to calculate the tag subject when a match is found or not found. The attributes are as follows:
Attribute description cookie the name of the HTTP cookie to be compared the name of the HTTP header to be compared the name of the HTTP request parameter to be compared the name of the bean or bean comparison, this attribute is the name location of the bean specified by the user. If the value of this attribute is set, it will match the scope at the specified position (index value). If the bean is compared, this attribute specifies the bean scope. If this parameter is not set, the search range is the constant value of the bean property name value to be compared from the page to the application scope property.
For example:
<Logic: Match parameter = "name" value = "xyz" location = "1">
The parameter name is a sub-string of the string XYZ from Index 1
</Logic: Match>
Check whether the request parameter named "name" is a sub-string of "XYZ, however, the substring must start from the index position 1 of "XYZ" (that is, the substring must be "y" or "YZ ").
2.2.2 duplicate mark
The <logic: iterate> tag is defined in the logical tag library, which checks the content of the TAG body based on the number of elements in a specific set. The collection type can be Java. util. iterator and Java. util. collection.
18
, Java. util. map or an array. There are three methods to define this set:
Returns a set of attributes using a running time expression.
Define the set as bean and use the name attribute to specify the name of the storage attribute.
Define a bean using the name attribute, and use the property attribute to define the bean attribute of a returned set.
The set of the current element is defined as a page-wide bean. The properties are as follows. All these properties can use runtime expressions.
Property description collection if the name attribute is not set, it specifies the name of the bean and script variable in the scope of the collection ID page to be repeated, it stores the name of the JSP bean in the indexed page scope of the current element in the set, it contains the maximum number of times that the current index length of the set is repeated after each repeat is completed as the bean name of the set, or a bean name, which is defined by the property attribute, is an index property at the beginning of a set Offset repeat as the bean attribute name of the set. If the bean name is specified, this attribute sets the bean scope. If not set, the search range from page to Application Scope type is the type of the currently defined page scope bean.
For example:
<Logic: iterate id = "currentint"
Collection = "<% = mylist %>"
Type = "java. Lang. Integer"
Offset = "1"
Length = "2">
<% = Currentint %>
</Logic: iterate>
The Code repeats two elements from the first element in the list and allows the current element to be used as a script variable of the page scope and Java. Lang. Integer type. That is to say, if mylist contains elements 1, 2, 3, 4, and so on, the code will print 1 and 2.
2.2.3 forwarding and redirection tags
Forwarding tag
<Logic: Forward> the flag can forward the response to a specific global actionforward. The actionforward type determines whether to use pagecontext to forward the response or use sendredirect to redirect the response. This tag has only one "name" attribute to specify the global actionforward name. For example:
<Logic: Forward name = "myglobalforward"/>
Redirection tag
<Logic: Redirect> flag is a powerful tool that can execute HTTP redirection. Based on the specified attributes, it can be redirected in different ways. It also allows developers to specify query parameters for the redirected URL. The attributes are as follows:
19
Attribute description forward maps the complete URL page resource relative path name of the actionforward href resource to the relative path name of the resource. The page name of the map type, request, session, or program attribute name, this includes the "name-value" parameter on the Redirection URL to be large (if the property is not set. Or the bean name with the map type property, which contains the same information (no Property is set) Name of the bean property of the property map type. The bean name is specified by the name attribute. If scope specifies the bean name, this attribute specifies the bean search range. If this parameter is not set, the search range is from page to application scope. paramid defines the name of the specific query parameter. paramname: the name of the bean of the string type, it contains the value of the query parameter (if the paramproperty attribute is not set); or a bean name, its attribute (specified in the paramproperty attribute) contains the name of the bean attribute of the query parameter value paramproperty string, which contains the search range of the bean defined by the query parameter value paramscope paramname
When using this tag, you must specify at least one attribute in forward, href, or page to indicate the resource to which the response is redirected.
2.3 HTML Tag
Struts HTML tags can be roughly divided into the following functions:
Display form elements and input controls
Show error message
Show other HTML elements
2.3.1 display form elements and input controls
Struts closely associates HTML forms with the actionform bean defined for form operations. The name of the field entered in the form corresponds to the attribute name defined in actionform bean. When the form is displayed for the first time, the input fields of the form are transplanted from the actionform bean. When the form is submitted, the request parameters are transplanted to the actionform bean instance.
All embedded markup that can be used in the <form> tag to display HTML input controls use the following attributes to define JavaScript Event Handlers.
Attribute description the onblur field loses the focus. The onchange field loses the focus, and the value is changed. The onclick field is clicked by the mouse. The ondblclick field is double-clicked and the onfocus field is received. The onkeydown field has the focus and a key. press
20
The onkeypress field has the focus and the onkeyup field has the focus when the key is pressed and released. the onmousedown mouse pointer is released to point to the field and the onmouseout mouse pointer is clicked to point to the field and the onmouseout mouse pointer is moved to the field. control, however, the pointer moves the onmouseover pointer to the outer side of the element, but the pointer moves the onmouseover pointer to the field inside the element, and the mouse button is released.
<Form> other general attributes that can be defined in an element include:
Attribute description accesskey definition shortcut key for access input field style definition style of input field styleclass definition style table class tabindex of input field tab order
A) Form tag
<HTML: form> the tag is used to display the HTML tag. You can specify the name of acitonform bean and Its Class Name. If these attributes are not set, a configuration file is required to specify the actionmapping to indicate which JSP page is currently entered and the bean name and class retrieved from the ing. If the specified name is not found in the scope specified by actionmapping, a new bean is created and stored. Otherwise, the bean is used.
<Form> tags can contain child tags corresponding to various HTML input fields.
<HTML: Form> the tag attributes are as follows:
Attribute describes actions related to the form. In configuration, this operation is also used to identify the encoding type of the form-related actionform bean enctype form HTTP Method in the focus form that needs to initialize the focus field method form the HTTP Method Name and form-related actionform Bean name. If this attribute is not set, the bean name will obtain the Javascript event handle when the onreset form is reset from the configuration information. The javascript event handle scope when the onsubmit form is submitted searches for the range of actionform beans. If no value is set, the full name of the format table class type actionform bean of the element styleclass used by style is obtained from the configuration file. If no configuration is set, it will be obtained from the configuration file
For example:
<HTML: Form Action = "validateemploee. Do" method = "Post">
</Html: Form>
The operation path related to the form is validateemployee, and the form data is transmitted through post. For this form, other information about the actionform bean, such as the bean name type and scope, is retrieved from the actionmapping of the specified form operation:
21
<Form-beans>
<Form-bean name = "empform" type = "com. example. employeeform"/>
</Form-beans>
<Action-mappings>
<Action Path = "/validateemployee"
Type = "com. example. validateexampleaction"
Name = "empform"
Scope = "request"
Input = "/employeeinput. jsp">
<Forward name = "success" Path = "/employeeoutput. jsp">
</Action>
</Action-mapping>
If the configuration file contains the preceding information and *. do is mapped to actionservlet. The name of the form-related actionform bean. The types and scopes are empform and COM. example. employeeform and request. you can also use the <HTML: Form> tag to define these attributes.
The following tags must be nested in the <HTML: Form> tag.
B) button and unmark
<HTML: button> a button control is displayed. <HTML: Cancel> A cancel button is displayed. The attributes are as follows:
Property description Property defines the tag on the name value button of the Request Parameter returned to the server when the form is submitted
C) reset and submit tags
The <HTML: reset> and <HTML: Submit> tags display the HTML reset button and submit button respectively.
D) text and partition labels
<HTML: Text> and <HTML: textarea> mark the HTML text box and text area respectively. The attributes are as follows:
Property description Property defines the name of the request parameter sent back to the server when the form is submitted, or the name of the bean whose attribute name is queried for the current value of the text element, it determines the value of the text box and partition. If this parameter is not set, the actionform name associated with this embedded form is used.
<HTML: Text> the tag has the following attributes:
Attribute description maxlength maximum number of characters that can be entered
22
Size text box size (number of characters)
<HTML: textarea> the tag attributes are as follows:
Attribute description number of rows in the rows partition Cols Partition Number of Columns
E) check box and check box mark
<HTML: checkbox> the flag displays the check box control. <HTML: multibox> mark the display of the HTML check box control. When the request object uses getparametervalues () to pass the check box name, a string array is returned. The attributes are as follows:
The name of the property description name bean, which is used to check whether the bean is displayed in the selected status. If no value is set, the actionfrom bean name associated with the embedded form is used. The name of the property check box is also the name of the bean property that determines whether the check box is displayed in the selected status. In the case of a check box, this attribute must be an array. Value: the value of the Request Parameter returned to the server when the check box is selected.
For example:
<HTML: checkbox property = "married" value = "y"/>
A check box named married returns a "Y" when the form is submitted ".
F) file tag
<HTML: File> the tag can display HTML file controls. The attributes are as follows:
The name of the property description name bean. Its property determines the content displayed in the file control. If this parameter is not set, the actionform bean Name property related to the embedded form is used to define the name of the request parameter sent back to the server when the form is submitted, and the set of content types that the accept server can process by determining the bean property name of the content displayed in the file control. It also filters the tag on the value button for the optional file types in the client browser dialog box, which can browse files in the local file system
G) radio button mark
<HTML: Radio> the tag is used to display the HTML radio button control. The attributes are as follows:
Attribute description name bean name, which is used to determine whether the radio button is displayed in the selected status. If no value is set, the actionfrom bean name associated with the embedded form is used. Property: the name of the request parameter sent back to the server when the form is submitted, and the name of the bean property used to determine whether the radio button is displayed in the selected status.
23
Value: The value returned to the server when the single-choice button is selected.
H) Hide tags
<HTML: hidden> the tag can display HTML to hide input elements. The attributes are as follows:
Attribute description name bean name, which is used to determine the current value of the hidden element. If no value is set, the actionfrom bean name associated with the embedded form is used. Property defines the name of the request parameter sent back to the server when the form is submitted, and the name value of the bean attribute used to determine the current value of the hidden element to initialize the value of the hidden input element.
I) password mark
<HTML: Password> the tag displays the HTML password control. The attributes are as follows:
Attribute description the name of the maximum number of characters name bean that maxlength can enter. Its attribute is used to determine the current value of the password element. If no value is set, the actionfrom bean name associated with the embedded form is used. Property defines the name of the request parameter sent back to the server when the form is submitted, and the name of the bean attribute used to determine the current value of the password element. When redisplay displays this field, if the corresponding bean property has been set with data, this property determines whether to display the size of the password content Size Field
J) Select tag
<HTML: Select> the tag displays the HTML Selection control. The attributes are as follows:
The attribute description multiple indicates whether the selection control allows the name of the name bean to be selected multiple times. The attribute determines which one to choose. If no value is set, the actionfrom bean name associated with the embedded form is used. Property defines the name of the request parameter sent back to the server when the form is submitted, and used to determine which option the name size of the bean attribute to be selected can display the number of options at the same time. value is used to indicate the options to be selected.
K) Option tag (this element needs to be nested in the <HTML: Select> tag)
<HTML: Option> the tag is used to display the set of HTML option elements. The attributes are as follows:
24
Attribute describes the name of the collection bean set, which is stored in the attribute of a certain scope. The number of options is the same as the number of elements in the set. The property can define the bean attribute used by the option value, while the labelproperty property defines the attribute labelname of the bean used by the option tag to specify the bean stored in a certain scope, this bean is a collection of strings and can be used together with the labelproperty and collection attributes to define the tags of <HTML: Option> elements (if the flag and value are different, the bean is used to define the bean stored in a certain scope. This bean returns a string set that can be used to write the value attribute name of the <HTML: Option> element. If this is a unique attribute, it defines the bean stored in a certain scope. This bean will return a string set that can be used to write <HTML: option> when the value property of an element is used together with the collection property, the name attribute of each independent bean to display the option value is defined. If it is not used together with the collection property, this property defines the name of the bean property specified by the name property (if there is a name property), or defines an actionform bean, this bean will return a set to write the option value
Let's take a look at some examples of this tag:
<HTML: Option collection = "optioncollection" property = "optionvalue"
Labelproperty = "optionlabel"/>
Flag assumes that there is a set named optioncollection in a specific scope. It contains some independent beans with the optionvalue attribute, and each attribute will be used as the value of an option. The flag of each option is defined by the optionlabel attribute of bean.
<HTML: Option name = "optionvalues" labelname = "optionlabels"/>
In the tag, optionvalues indicates a bean stored in a specific scope. It is a string set that can be used to write the option value. optionlabels indicates a bean stored in a specific scope, it is also a string set that can be used to write the flag of the option.
2.3.2. Mark the error message
<HTML: errors> tags can be combined with actionerrors to Display error messages. This tag first reads the message keyword errors. header from the resource file of the current region, and then displays the message text. Next, it will be stored in the actionerrors object (usually stored in the action as a request parameter. under the error_key keyword), read the message keyword of a single actionerror object, read and format the corresponding messages from the resource file in the current region, and display them. Then it reads and displays the message corresponding to the errors. footer keyword.
You can define the property attribute to filter messages to be displayed. The value of this attribute should correspond to the keyword of the actionerror object stored in the actionerrors object. The attributes are as follows:
Attribute description bundle indicates the name of the application scope attribute. It contains message resources. Its default value is acion. message_key locale, indicating the name of the session scope attribute. It stores information about the region where the user is currently logged on. The default value is action. error_key.
25
Name indicates the name of the request property, which stores the actionerrors object. The default value is action. error_key property. This attribute specifies the keyword for storing each independent actionerror object in the actionerrors object. It can filter messages.
Example:
<HTML: errors/>
Displays all errors in the set.
<HTML: errors property = "missing. Name"/>
Displays errors stored in the missing. Name keyword.
2.3.3. Other HTML tags
The struts HTML Tag also defines the following tags to display other HTML elements:
<HTML: HTML>: display HTML elements
<HTML: img>: displays image tags.
<HTML: link>: displays html links or anchor points.
<HTML: rewrite>: Creates a URI without the anchor tag.
For more information about these tags, see the struts documentation.
2.4. template tag
Dynamic templates are powerful means of modular web page layout design. The struts template tag library defines custom tags to implement dynamic templates.
2.4.1. Insert tag
<Template: Insert> the tag can insert a dynamic Template into the JSP page of the application. This tag has only one template attribute to define the template JSP page. The page to be inserted to the template is specified by multiple <template: Put> tags, which are defined as the subject content of the <template: Insert> tag.
2.4.2. Placement tag
<Template: Put> the tag is used internally by the <template: Insert> tag to specify the resource to be inserted to the template. The attributes are as follows:
Attribute description content defines the content to be inserted, such as a JSP file or HTML file direct. If this is set to true, the content specified by the content attribute will be directly displayed on JSP instead of as the name role of the content containing the file name to be inserted. If this attribute is set, content can be inserted only when the current legal user has a specific role.
26
2.4.3. Mark
On the template JSP page, use the <template: Get> tag to retrieve the resources inserted to the JSP page by the <template: Put> tag. The attributes are as follows:
The attribute description name is the name of the inserted content marked by <template: Put> role. If this attribute is set, the content can be searched only when the current legal user has a specific role.
2.4.4. Use template tag
First, compile a template JSP page, which will be used by all web pages:
<HTML>
<% @ Taglib uri = "/template" prefix = "template" %>
<Head>
<Title> </title>
</Head>
<Body>
<Table width = "100%" Height = "100%">
<Tr Height = "10%">
<TD>
<Template: Get name = "Header"/>
</TD>
</Tr>
<Tr Height = "80%">
<TD>
<Template: Get name = "content"/>
</TD>
</Tr>
<Tr Height = "10%">
<TD>
<Template: Get name = "footer"/>
</TD>
</Tr>
</Table>
</Body>
</Html>
We name this file template. jsp. This file uses the <template: Get> tag to obtain the content provided by the <template: Put> tag on the JSP page, and displays the content in an HTML table. The three contents are the title, content, and footer. The typical content JSP will be like this:
<% @ Taglib uri = "/template" prefix = "/template" %>
<Template: insert template = "template. jsp">
<Template: Put name = "Header" content?#header.html "/>
27
<Template: Put name = "content" content = "employeelist. jsp"/>
<Template: Put name = "footer" content?#footer.html "/>
</Template: Insert>
The JSP page of this application uses the <template: insert tag to define the template, and then uses the <template: Put> tag to place the resource specified by the specific content name to the template JSP page. If we have hundreds of pages with the same layout but suddenly want to change this template, we only need to change the template. jsp file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.