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 }