欢迎光临
我们一直在努力

Struts 中 Multibox 的用法-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

在 actionform 中定义一个数组 string[] selectedoptions 用于存放复选框被选中的值,

数组 labelvaluebean[] possibleoptions 用于显示所有的复选框的值。

import org.apache.struts.util.labelvaluebean; . . . public class myactionform extends actionform {   private labelvaluebean[] possibleoptions;   private string[] selectedoptions;    public myactionform()   {      // initialise the labelvaluebeans in the possibleoptions array.     labelvaluebean[] lvbeans = new labelvaluebean[4];      lvbeans[0] = new labelvaluebean("alpha", "a");     lvbeans[1] = new labelvaluebean("beta", "b");     lvbeans[2] = new labelvaluebean("charlie", "c");     lvbeans[3] = new labelvaluebean("delta", "d");      this.possibleoptions = lvbeans;   }    public labelvaluebean[] getpossibleoptions()   {     return possibleoptions;   }    public string[] getselectedoptions()   {     return selectedoptions;   }    public void setselectedoptions(string[] selectedoptions)   {     this.selectedoptions = selectedoptions;   } }

在 jsp 中使用以下代码:

<logic:iterate name="myactionform" id="item" property="possibleoptions">   <html:multibox property="selectedoptions">     <bean:write name="item" property="value" />   </html:multibox>     <bean:write name="item" property="label" /><br /> </logic:iterate>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Struts 中 Multibox 的用法-JSP教程,Java技巧及代码
分享到: 更多 (0)