The page uses the struts2 label to get the object property value in the List. Summary of common Struts2 labels

Source: Internet
Author: User

The page uses the struts2 label to get the object property value in the List. The Struts2 common labels summarize the struts2 label List.

<% @ Taglib prefix = s uri =/struts-tags %>

 

 

 

Struts2 common labels
1. Introduction
1. Role of Struts2
The Struts2 tag Library provides topic and template support, which greatly simplifies the compilation of view pages. In addition, the topics and templates of struts2 provide excellent scalability. Achieves better code reuse. Struts2 allows the use of custom components on the page, which can fully meet the complex and variable page display requirements in the project.
The Struts2 tag library has a huge improvement. The tags of the struts2 tag library do not rely on any performance Layer Technology. That is to say, strtus2 provides most of the labels and can be used in various performance technologies. Including the most commonly used jsp pages, it can also be said that the use of template technologies such as Velocity and FreeMarker
2. Struts2 Classification
(1) UI tags: (User Interface, User Interface) tags are mainly used to generate HTML element tags. UI tags can be classified into Form tags rather than form tags.
(2) Non-UI tags are mainly used for data access, logical control, and other tags. Non-UI labels can be divided into Process Control labels (including labels used to implement process control such as branch and loop) and data access labels (mainly including the value of ValueStack output by users and functions such as internationalization)
(3) ajax tag
3. Preparations before using the Struts2 label:
(1) introduce the tag library on the jsp page of the tag to be used:
<% @ Taglib uri =/struts-tags prefix = s %>
(2) Declare the tag to be used in web. xml. This is the Introduction Method of struts2 2.3.1.2.

Struts2
Org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter

4. Use of labels
(1) property tag
Used to output the specified value:





The preceding method allows you to access the attributes of a class in a package. study () is the method for accessing the class and outputs it.

 


The following code is used to access attributes within a certain range.
<%
// Use the pageContext object to input the memory value in the page range to verify that # the attr search sequence starts from the page, and the search sequence is page, reques, session, and application.
When the set value is stored, the request is saved. when accessing the jsp page, you do not need to add any identifiers to directly access it. If different scopes are different,
PageContext. setAttribute (name, laoowang, PageContext. PAGE_SCOPE );
%>


Assume that classes of different scopes are set in action.
Access to tags in different scopes:
 

Obtain the object Value in requet.
Method 1:


Method 2:


Method 3:


Method 4:


Method 5: $ {requestScope. user1.realName} | |$ {requestScope. user1 ['realname']}

Sixth:
The attr object is found by page ==> request sessionapplictio


Get the value in the session
Method 1:


Method 2:


Method 5: $ {sessionScope. user1.realName} | $ {sessionScope. user1 ['realname']}

Get the object Value in application
Method 1:


Method 2:


Method 5: $ {applicationScope. user1.realName} | $ {applicationScope. user1 ['realname']}

(2) Use of iterator labels
First: list Set














Second: Use in the map set
Map set

 


Traverse Map:



:::

 

Third: Set Variables

Traversal set :::



3000}>






3000)}>

 
Note: users is the User object and price is an attribute in the User.

 

Brief Introduction to iterator:
The iterator label is used to iterate the Set. The Set here contains List, Set, and array.


Red Blue >



Value: an optional attribute that specifies the set to be iterated. If this attribute is not set, the set at the top of the ValueStack stack is used.
Id: an optional attribute that specifies the id of the element in the set.
Status: an optional attribute that specifies the IteratorStatus instance during iteration. The instance contains the following methods:
Int getCount () returns several elements of the current iteration.
Int getIndex () returns the index of the element of the current iteration.
Boolean isEven (), returns whether the index of the element being iterated is an even number.
Boolean isOdd (), returns whether the index of the element being iterated is an odd number.
Boolean isFirst (), returns whether the currently iterated element is the first element.
Boolean isLast (), returns whether the currently iterated element is the last element.


(3) Use of if else statements


23


21


Not all

(4) URL tag


Laowangang
12

Test URL

The above two The tag function is the same.
(5) data tag
<%
PageContext. setAttribute (birth, new Date (200,03, 10), PageContext. REQUEST_SCOPE );
%>


This label is output according to the format.

(6) Form

 

From form


























<%
// Transfer the value from the server
PageContext. setAttribute (sex, male, PageContext. REQUEST_SCOPE );
PageContext. setAttribute (sex1, male, PageContext. REQUEST_SCOPE );
%>









 

 

Related Article

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.