Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Struts2 iterator

2025-03-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use Struts2 iterator, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

First, Struts2 iterator introduction.

The main function of this tag is to drop out of the collection.

The value attribute represents the value that needs to be displayed.

The status property, which is used to save some of the state values of the drop generation.

Note: 1. If you need to reference a value in valueStack, you need to use this form.

/ / userList is stored in the Request in the action section, so use the # plus attribute name to refer to the value.

two。 If the value of the collection is through the action method, suppose we have a getListMenu method in our action that returns a List collection.

We can refer to this collection in the following form and output it with s:iterator.

3.Struts2 iterator's value uses defined methods, such as:

/ / so the output value of the drop generation is 1.2.3.4 these four values.

Second, output the specific value in Struts2 iterator, if, in the object in our list above, there are two properties, both of which are of type String, one is name and the other is url.

We can quote it this way.

1. / / in this way we will be able to output the value of the name property of the substitute object.

two。 What should we do if we want to use it to process the jumped url?

The expression of / /% {} ognl, which can process the value of url

In fact, it is an absolute path. In this way, we can deal with some path problems caused by jump switching.

Reason: because later, the current object should be at the top of the ValueStack, so of course url is actually the object's url property.

Third, use ognl to output the corresponding value.

Using this expression, a text box is generated and, if there is a loginNames attribute in request.attribute, it will be used as the default value for these text boxes.

If you only use # request.loginNames inside the struts2 tag, it will not display any value, pay attention to the% {} appended to the outside, it will be used normally.

If you want to output a file directly like the EL language, such as an innerHTML text with a value of # request.loginNames, we just need to use: to make it work!

Note:

1. ${} is the% {} form of the EL language. The form of% {} is used inside the struts2 tag, and the ${} EL language can be used outside the tag. If you use ${} inside the struts2 tag, the following error message will appear:

According to TLD or attribute directive in tag file, attribute value does not accept any expressions

two。 Very often, we use some tags of struts2, and the attribute needs to accept the collection. If the collection is stored in the request,session, or the value stack (not the top of the stack of the root object), you can use the # variable name. If the value obtained is obtained through a specific method in Action, you need to use a method such as value= "userList", only removing the previous #.

3. Maybe I am not wrong about some value stack, root object, and some ognl knowledge at the top of the stack. If you find a problem, please help to point it out. Thank you.

Thank you for reading this article carefully. I hope the article "how to use Struts2 iterator" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report