Struts2 checkbox复选框 传值/取值

jsp 代码:

 

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
< prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    ">
    Struts2 复选框数据传值
 
  function checkAll(){
   var listc = document.getElementsByName("listCheck");
   if(document.getElementById("CheckAll").checked==true){
    for(var i=0;i      listc[i].checked=true;
    }
   }else{
    for(var i=0;i      listc[i].checked=false;
    }
   }
  }
 
  
  
       
     全选

     111

     222

     333

     444

     555 

     
    
    
           
    
  

 

struts.xml:




 
  
   
    /index.jsp
   

  
 
   

Action 类:

package com.okttl.web.action;

import java.util.List;

import com.okttl.entity.Users;
import com.opensymphony.xwork2.ActionSupport;

public class CheckBoxTestAction extends ActionSupport {

 private List listCheck;
 
 public List getListCheck() {
  return listCheck;
 }
 public void setListCheck(List listCheck) {
  this.listCheck = listCheck;
 }


 public String findAll(){
   System.out.println(listCheck);
  return SUCCESS;
 }
}

 

 

-----传值判断是否要选中复选框


     
             
            
                checked="checked"
            
        
    /> 
       <%--checkbox的结尾--%>


bookList是action中的List属性,查询数据库所有的book放值栈中
bookIds是action中的Integer[]属性,某个人已经选的书

你可能感兴趣的:(jsp,&,html)