title: how to get multiple checkbox value in struts 2 using checkbox list
body: <p>Hi I am new to struts 2 ,
  Can somebody tell me how to get multiple checkbox value in struts 2.
  So far i have developed the code which is as follows.
  i am getting the error </p>
  
  <pre><code>tag 'checkboxlist', field 'list', name 'subscribe': The requested list key 'subscription' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
      at org.apache.struts2.components.Component.fieldError(Component.java:240)
      at org.apache.struts2.components.Component.findValue(Component.java:333)
      at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
      at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:875)
      at org.apache.struts2.components.UIBean.end(UIBean.java:523)
      at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
      at jsp_servlet.__step1._jsp__tag6(__step1.java:371)
      at jsp_servlet.__step1._jsp__tag0(__step1.java:148)
      at jsp_servlet.__step1._jspService(__step1.java:86)
      at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
  </code></pre>
  
  <p>My jsp page to get the values is</p>
  
  <pre><code> &lt;link href="style.css" rel="stylesheet" type="text/css"/&gt;
   &lt;%@ taglib uri="/struts-tags" prefix="s" %&gt;
  
   &lt;table class="profiletable" align="center"&gt;
  &lt;tr&gt;
      &lt;td align="center"&gt;&lt;h2&gt;Upload User Profile&lt;/h2&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td align="center"&gt;&lt;s:form action="upload" method="post"&gt;
  &lt;s:textfield name="fname" label="First Name"&gt;&lt;/s:textfield&gt;
  &lt;s:textfield name="lname" label="Last Name"&gt;&lt;/s:textfield&gt;
  &lt;s:radio name="mstatus" label="Martial Status" list="{'Single','Married'}"&gt;&lt;/s:radio&gt;
  &lt;s:radio name="gender" label="Gender" list="{'male','female'}"&gt;&lt;/s:radio&gt;
  &lt;s:select list="{'India','USA','UK','Germany','France','Australia'}" label="Country" name="country"&gt;&lt;/s:select&gt;
   &lt;s:checkboxlist label="Letter you want to subscribe" name="subscribe" list="subscription" /&gt;
    &lt;s:submit value="upload profile" align="center"&gt;&lt;/s:submit&gt;
  &lt;/s:form&gt;&lt;/td&gt;
  &lt;/tr&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p>my jsp page to show the values is</p>
  
  <pre><code>&lt;%@ taglib uri="/struts-tags" prefix="p" %&gt;
  &lt;h2&gt;Profile uploaded sucessfully&lt;/h2&gt;
   First Name:&lt;p:property value="fname"/&gt;&lt;br/&gt;
  Last Name:&lt;p:property value="lname"/&gt;&lt;br/&gt;
  Martial status:&lt;p:property value="mstatus"/&gt;&lt;br/&gt;
  Gender:&lt;p:property value="gender"/&gt;&lt;br/&gt;
  Country:&lt;p:property value="country"/&gt;&lt;br/&gt;
  Letters Subscribed:&lt;p:property value="subscribe"/&gt;/&gt;
  </code></pre>
  
  <p>my action file is</p>
  
  <pre><code>package com.javapoint;
  
  import java.util.ArrayList;
   import java.util.List;
  
  import com.opensymphony.xwork2.ActionSupport;
  
  
  
   public class UploadProfile extends ActionSupport {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  private String fname;
  private String lname;
  private String mstatus;
  private String gender;
  private String country;
  private String subscribe;
  private List&lt;String&gt; subscription;
  
  public String getFname() {
      System.out.println("inside getfname");
      return fname;
  }
  public void setFname(String fname) {
      System.out.println("inside getfname");
      System.out.println("the firstname set is "+fname);
      this.fname = fname;
  }
  public String getLname() {
  
      return lname;
  }
  public void setLname(String lname) {
      this.lname = lname;
      System.out.println("the lastname set is "+ lname);
  }
  public String getMstatus() {
      return mstatus;
  }
  public void setMstatus(String mstatus) {
      this.mstatus = mstatus;
  }
  public String getGender() {
      return gender;
  }
  public void setGender(String gender) {
      this.gender = gender;
  }
  public String getCountry() {
      return country;
  }
  public void setCountry(String country) {
      this.country = country;
  }
  
  public String getSubscribe() {
      return subscribe;
  }
  public void setSubscribe(String subscribe) {
      this.subscribe = subscribe;
  }
  public List&lt;String&gt; getSubscription() {
      return subscription;
  }
  public void setSubscription(List&lt;String&gt; subscription) {
      this.subscription = subscription;
  }
  public UploadProfile(){
      subscription=new ArrayList&lt;String&gt;();
      subscription.add("Politics");
      subscription.add("Sports");
      subscription.add("Editorial");
      subscription.add("Gadgets");
      subscription.add("Overdrive");
  }
  public String execute()throws Exception{
      System.out.println("inside execute");
      if(fname!=null){
      return "profileuploaded";
      }else{
          return "error";
  
      }
  }
  
  public String display(){
  
      return NONE;
  }
  
  
  }
  </code></pre>
  
  <p>My struts.xml file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
  Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"&gt;
  &lt;struts&gt;
   &lt;package name="default" extends="struts-default"&gt;
  
  &lt;action name="product" class="com.javapoint.Product"&gt;
  &lt;result name="success"&gt;welcome.jsp&lt;/result&gt;
  &lt;/action&gt;
  &lt;action name="upload" class="com.javapoint.UploadProfile"&gt;
  &lt;result name="profileuploaded"&gt;ProfileUploaded.jsp&lt;/result&gt;
   &lt;result name="error"&gt;index.jsp&lt;/result&gt;
  &lt;/action&gt;
  &lt;/package&gt;
    &lt;/struts&gt;    
  </code></pre>
  
  <p>and my web.xml file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app&gt;
  &lt;filter&gt;
  &lt;filter-name&gt;struts2&lt;/filter-name&gt;
  &lt;filter-class&gt;
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    &lt;/filter-class&gt;
   &lt;/filter&gt;
    &lt;filter-mapping&gt;
     &lt;filter-name&gt;struts2&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
    &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;step1.jsp&lt;/welcome-file&gt;
     &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p></p>