How to take values of only selected checkbox in Action class in struts2 and jsp

后端 未结 2 1199
难免孤独
难免孤独 2020-12-20 03:58

Here I am displaying 24 checkboxes.I want to get all the values of checked checkboxes in action class and insert it as a new record inside database.Inserting will be done on

2条回答
  •  春和景丽
    2020-12-20 04:36

    I just changed my datatype of variable from boolean to string[] . It will store the values of the checkbox selected. Below is my jsp.

    
    
            

    Rangabhoomi Fire NOC

    Below is my action class

    package com.checkboxInStruts2;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class CheckboxAction extends ActionSupport 
    {
        private String checkMe[];
    
        public CheckboxAction() {
            // TODO Auto-generated constructor stub
        }
    
        public String[] getCheckMe() {
            return checkMe;
        }
    
        public void setCheckMe(String[] checkMe) {
            this.checkMe = checkMe;
        }
        @Override
        public String execute() throws Exception {
            // TODO Auto-generated method stub
            for(int i=0;i

    and for display use below tag on jsp.It will display the array of string values of selected checkboxes.

    
    

提交回复
热议问题