Java – Struts getting values from checkbox

javajspstrutsstruts-1

I am having a struts app with a jsp page that populates check boxes from collection as below

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"));
   }

}

I am Populating the JSP page with the values from collection as Below

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>

The Output is as below

enter image description here

Now while submitting the form I want the values from the Checked Check box alone.I don't want to write 5 separate lines for getting values from each check box. How to do this

Thanks for the help.

Best Solution

Struts has a tag that fit your needs : multibox, you can see these links :

And convert your collection to an array