【问题标题】:Struts getting values from checkboxStruts 从复选框中获取值
【发布时间】:2013-05-16 12:28:55
【问题描述】:

我有一个带有 jsp 页面的 struts 应用程序,该页面填充来自集合的复选框,如下所示

UserDetails.java

public class UserDetails extends ActionForm 
{
   private Collection userSkills;   
   .
   //Getters and Setters for userSkills      
   .
   .
   .
   public void reset(ActionMapping mapping, HttpServletRequest request)
   {
    userSkills = new ArrayList();
    userSkills.add(new LabelValueBean("java", "Java"));
    userSkills.add(new LabelValueBean("mysql", "MySQL"));
    userSkills.add(new LabelValueBean("php", "PHP"));
    userSkills.add(new LabelValueBean("css", "CSS"));
    userSkills.add(new LabelValueBean("html", "Html"));
   }

}

我正在使用以下集合中的值填充 JSP 页面

RegisterUser.jsp

<logic:iterate property="userSkills" id="userDet" name="User">
   <html:checkbox property="label" name="userDet" indexed="true">
      <bean:write property="label" name="userDet"></bean:write>
    </html:checkbox>
</logic:iterate>

输出如下

现在,在提交表单时,我只需要 Checked Check 框中的值。我不想编写 5 行单独的行来从每个复选框中获取值。如何做到这一点

感谢您的帮助。

【问题讨论】:

    标签: java jsp struts struts-1


    【解决方案1】:

    Struts 有一个适合你需要的标签:multibox,你可以看到这些链接:

    并将您的集合转换为数组

    【讨论】:

      【解决方案2】:

      在 Userdetails.java 中

          public class UserDetails extends ActionForm { 
          private String[] userSkills;
         //setter and getter for userSkills
      }
      

      在 RegisterUser.jsp 中

      <html:multibox property="userSkills" value="java"/> java
      <html:multibox property="userSkills" value="mysql"/> mysql
      <html:multibox property="userSkills" value="php"/> php
      

      尝试使用这个

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-26
        • 1970-01-01
        • 1970-01-01
        • 2018-09-10
        • 2017-12-12
        相关资源
        最近更新 更多