Usage of struts2 checkbox value passing

Source: Internet
Author: User

Checkbox should be used for batch submission when writing data to the background. Baidu once found the relatedArticleVery few. After half a day, Zhang finally got it ready. Remember it first.

It should be noted that the checkbox value of HTML is not, S: checkbox

If multiple checkboxes with the same name are submitted, struts2 uses list to receive them.

 

Page:

 1   <  Form  Name  = "Checkform"  ID  = "Checkform"  Method  = "Post"  Action  = "/User/deleteusers"  > 2   3  <  Ul  >  4   5  <  Li  > <  Input  Type  = "Checkbox"  Name  = "Checkall"  ID  = "Checkall" Onclick  = "Selectallbox ()"  /> </  Li  >  6   7  <  Li  > <  Input  Type  = "Checkbox"  Name  = "Tags"  Value  = "1"  /> </  Li  >  8   9  <  Li  > <  Input  Type  = "Checkbox"  Name  = "Tags"  Value  = "2"   /> </  Li >  10   11  <  Li  > <  Input  Type  = "Checkbox"  Name  = "Tags"  Value  = "3"   /> </  Li  >  12  13  <  Li  > <  Input  Type  = "Checkbox"  Name  = "Tags"  Value  = "4"   /> </  Li  >  14   15  < Li  > <  Input  Type  = "Checkbox"  Name  = "Tags"  Value  = "5"   /> </  Li  >  16   17  <  Li  > < A  Href  = "Javascript: Document. getelementbyid ('checkform'). Submit ();"  > Submit </  A  > </  Li  >  18   19  </  Ul  >  20   21  </  Form  > 

 

Select All JS:

 1   Function  Selectallbox (){  2   3  VaR Checkall = Document. getelementbyid ("checkall" );  4   5  VaR Tags = Document. getelementbyname ("tags" ); 6   7        If (Checkall. Selected = True  ){  8   9  For ( Int I = 0; I <tags. length; I ++ ){  10   11 Tags [I]. Selected = True  ;  12  }  13 } Else  {  14   15  For ( Int J = 0; j <tags. length; j ++ ){  16   17 Tags [I]. Selected = False  ;  18   }  19  }  20   21 }

 

Struts. xml configuration:

 1   <  Package  Name  = "Userpk"  Namespace  = "/User"  Extends  = "Struts-Default"  >  2   3  <  Action  Name  = "Deleteusers"  Class  = "Com. txm. Action. useraction"  Method  = "Deleteusers"  >  4   5  <  Result  Name  = "Success"  > /Admin/Main. jsp</  Result  >  6  </  Action  >  7   8   </  Package  > 

 

Useraction:

 1   Private  List tags;  2  3   Public  String deleteusers (){  4   5 System. Out. println ("class --> useraction, Method --> deleteusers" );  6   7   System. Out. println (TAGS );  8   9  Return  Success;  10   11  }  12   13   Public   Void  Settags (list tags ){  14   15  This . Tags = Tags;  16   17   }  18   19   Public  List gettags (){ 20   21  Return   This  . Tags;  22   23 }

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.