简体   繁体   English

使用struts Logic taglib生成选择选项

[英]Generating Select Options using struts Logic taglib

Is it possible to display Select box with options filled with numbers as below in struts by using struts Logic taglib. 是否可以通过使用struts Logic taglib在struts中显示选择框,其中的选项用数字填充,如下所示。

<select>
 <option value="20">20</option>
 <option value="21">21</option>
 <option value="22">22</option>
 <option value="23">23</option>
 <option value="24">24</option>
 <option value="25">25</option>
</select>

Some thing like one below 像下面这样的东西

<logic:iterate start="20" end="25" id="Num">
  <option value="Num">Num</option>
</logic:iterate>

Struts' logic iterate tag is meant to iterate over a collection : Struts的逻辑迭代标签旨在对集合进行迭代:

Repeats the nested body content of this tag once for every element of the specified collection, which must be an Iterator, a Collection, a Map (whose values are to be iterated over), or an array. 对指定集合的​​每个元素重复一次此标签的嵌套主体内容,这些元素必须是Iterator,Collection,Map(要迭代其值)或数组。

Source : logic iterate definition 来源: 逻辑迭代定义

If the only purpose is to generate a simple select with the index as value for options, use JSTL instead : 如果唯一的目的是使用索引作为选项的值来生成简单的选择,请改用JSTL:

<select>
    <c:forEach begin="20" end="25" varStatus="loop">
        <option value="${loop.index}">${loop.index}</option>    
    </c:forEach>
</select>

It is not a problem to use JSTL rather than struts tags : 使用JSTL而不是struts标记不是问题:

The Struts team encourages the use of the standard tags over the Struts specific tags when possible. Struts团队鼓励在可能的情况下使用标准标签而不是Struts特定标签。

Don't forget to import the JSTL core taglib : 不要忘记导入JSTL核心taglib:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

In struts 2, select tag is used to display the dropdown and it takes a collection as input. 在struts 2中,select标记用于显示下拉列表,并以集合作为输入。 More info on this can be found at 有关更多信息,请参见

apache official page for select tag 选择标签的apache官方页面

and a good tutorial on select tag 以及有关select标签的好教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM