Struts1.x tag Library

Source: Internet
Author: User

1) configurations required to use the tag Library:

Add internationalized configuration: first copy <message-resources parameter = "messageresources"/> to the struts-config.xml. Copy the file messageresources. properties to the src directory.

2) Deploy the project

3) use the bean tag in struts on the JSP page.

First, you must introduce the struts tag library to use struts labels. The import is as follows; <% @ taglib prefix = "" uri = "%> where prefix and Uri can be found in struts. jar --> META-INF --> TLDs --> struts-bean.tld. As follows: <shortname> bean </shortname> corresponds to prefix
<URI> http://struts.apache.org/tags-bean </uri> corresponds to the URI, which is introduced as follows: <% @ taglib prefix = "Bean" uri = "http://struts.apache.org/tags-bean" %>

The bean tag can be used after the bean tag library is introduced. The bean tag library mainly contains the bean: Write tag. BEAN: common attributes of the write tag are as follows:

Name attribute: Name = "variable name". The value of the variable is retrieved Based on the name of the corresponding variable in SCOP. For example: <Bean: write name = "hello"/>, the tag is executed on the server.

Filter attribute: the default value of filter = "true" is true. HTML content is output as is, that is, it is not parsed. If it is set to false, the HTML Tag is parsed and only the content is output.

Format attribute: format the date. If this attribute is not used, it is output as is. Example: format = "yyyy-mm-dd hh: mm: SS ". format is also used to format numbers. The usage is as follows: format = "###,###. ### "indicates a comma at every three digits. Retain three digits after decimal point. # It can also be replaced by 0.

Property: used to retrieve a property in an object. The property value is the name of the property of the object to be retrieved. Navigation is supported.

4) use the logic tag in struts on the JSP page.

Similarly, to use logic tags, you must introduce the logic tag library. Method. You can use it after it is introduced.

Logic: Empty and logic: notempty labels have the following attributes:

Name attribute: the value of name is equal to the value to be judged or the name of the object, which will be searched within the SCOP range. The result is null or not empty. If it does not exist, it is also empty. Equivalent

The main attributes of the logic: Present and logic: notpresent labels are:

Name attribute: the value of name is equal to the value to be judged or the name of the object, which will be searched within the SCOP range. The result is or does not exist.

 

Logic: main attributes of the iterate label: (The iterate label is used together with the empry above)

Name attribute: the name of the variable in SCOP.

Id attribute: ID is used to set a temporary variable. ID = "temporary variable name". During iteration, the value is placed in this variable.

Property: used to retrieve a property in an object. The property value is the name of the property of the object to be retrieved. Navigation is supported.

Use the beanwrite label in the iterate label

Example:

<Li> JSP script </LI> <br>
<Table border = "1">
<Tr>
<TD> name </TD>
<TD> age </TD>
<TD> group </TD>
</Tr>
<%
List userlist = (list) request. getattribute ("userlist ");
If (userlist = NULL | userlist. Size () = 0 ){
%>
<Tr>
<TD colspan = "3"> no matching data! </TD>
</Tr>
<%
} Else {
For (iterator iter = userlist. iterator (); ITER. hasnext ();){
User user = (User) ITER. Next ();
%>
<Tr>
<TD> <% = user. GetUserName () %> </TD>
<TD> <% = user. getage () %> </TD>
<TD> <% = user. getgroup (). getname () %> </TD>
</Tr>
<%
}
}
%>
</Table>

<P>
<Li> label </LI> <br>
<Table border = "1">
<Tr>
<TD> name </TD>
<TD> age </TD>
<TD> group </TD>
</Tr>
<Logic: Empty name = "userlist">
<Tr>
<TD colspan = "3"> no matching data! </TD>
</Tr>
</Logic: Empty>
<Logic: notempty name = "userlist">
<Logic: iterate id = "U" name = "userlist">
<Tr>
<TD>
<Bean: write name = "U" property = "username"/>
</TD>
<TD>
<Bean: write name = "U" property = "Age"/>
</TD>
<TD>
<Bean: write name = "U" property = "group. Name"/>
</TD>
</Tr>
</Logic: iterate>
</Logic: notempty>
</Table>

 

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.