References: formatting date output using struts tags, struts2 JSP page traversal list set, after modification, upload the set to action, Struts iterator tag, struts2 configuration related issues, and Struts 2.1.6 tag reference, the most reliable official document. This takes a good time to study!
There are four common methods to read page values:
<S: property value = "username"/>
$ {Username}
<S: property value = "# request. username"/> (# session. # application. Similar)
<S: property value = "% {username}"/>
Format date output
1.Format with <s: Date>. Example:
<S: Date Name= "Birthday" Format= "Yyyy-mm-dd"/>
That is, the attribute birthday is output in the format of yyyy-mm-dd.
2.Format with <s: param>. Example:
<S: textfield name = "Birthday">
<S: Param name = "value"> <s: Date name = "Birthday" format = "yyyy-mm-dd"/> </S: param>
</S: textfield>
Or
<Input type = "text" value = "<s: Date name =" Birthday "format =" yyyy-mm-dd "/>"/>
3.Going International
First, configure struts. Custom. i18n. Resources = globalmessages in struts. properties.
Add the following content to the globalmessages_zh_cn.properties and globalmessages_en_us.properties files:
Global. datetime = {0, date, yyyy-mm-dd hh: mm: SS}
Global. Date = {0, date, yyyy-mm-dd}
Finally, you can use the following statement on the page to format and output the date.
<S: textfield Name= "Birthday"
Value= "% {Gettext ('Global. date', {birthday })}"/>-- Golbal. Date Style
<S: textfield Name= "Birthday"
Value= "% {Gettext ('Global. datetime', {birthday })}"/>-- Global. datetime Style
Output table
Use the iterator tag of struts to traverse the output:
<S:Iterator VaR="List" Value="Entplist" Status="Sta">
<Tr>
<TD><S:Property Value="# Sta. Index" />
</TD>
<TD>$ {List. ename}</TD>
<TD>$ {List. loginname}</TD>
<TD>$ {List. Location}</TD>
<TD>$ {List. Email}</TD>
</Tr>
</S:Iterator>
Struts2 S: iterator can traverse any array and set in the data stack.
Iterator has three attributes:
Value: The set that is iterated over;
ID: Specifies the element ID in the set;// Deprecated. Use 'var' instead after struts 2.1.x
Status: Index of the iteration element;
1: JSP page definition element writing array or list
<S: iterator Value="{'1', '2', '3', '4', '5 '}"ID='Number' >
<S: Property Value='Number' />A
</S: iterator>
The result is 1a2a3a4a5a.
2: Index usage
The index status in the traversal Control <s: iterator> of struts2.0:
1: Odd (ODD)
2: First (first index)
3: Even (even)
4: Last (Tail Index)
5: Index)
If status is specified, each iteration of data has an iteratorstatus instance, which has the following methods:
int getcount () returns several elements of the current iteration
int getindex () returns the index of the current element
Boolean iseven (): Of course, whether the index is even
Boolean isfirst () whether it is the first element
Boolean islast ()
Boolean isodd () whether the index of the current element is odd
<S: iterator Value="{'A', 'B', 'C '}"ID='Char'Status='St' >
<S: IfTest="# St. Even" >
The current index is odd:<S: Property Value='# St. Index' />
</S: If >
Current element value:<S: Property Value='Char' />
</S: iterator>
Check whether test is a keyword.If Test is the same
3: traverse Map
Value can also be the java. util. map object in the data stack.
<S: iterator Value="Map"ID="ID"Status="St" >
Key:<S: Property Value='Key' />
Value:<S: Property Vlaue='Value' />
</S: iterator>