jsp:<c:forEach var="list" items="${list}">
  <tr><td><input type="checkbox" name="publish" id="publish" value="${list.anc_who }"/></td>
      <td>${list.anc_title}</td>
      <td id="anc_content">${list.anc_content }
                           <input type="hidden" name="anc_id" value="${list.anc_id }"/></td>
   </tr>
</c:forEach>
   <tr><td><input type="submit" value="确定" /><input type="hidden" name="count" id="count" value="" /></td>
       <td id="AncTitleError" style="display:none;"><s:property value="errors.anc_title[0]"/></td>
       <td><input type="reset" value="取消" /></td>
   </tr>count是js计算用户所选择的checkbox的个数Action:
         Integer anc_id[];
Integer anc_who;
int count=0; public Integer getAnc_who() {
return anc_who;
}
public void setAnc_who(Integer anc_who) {
this.anc_who = anc_who;
} public int getCount() {
return count;
} public void setCount(int count) {
this.count = count;
} public Integer[] getAnc_id() {
return anc_id;
} public void setAnc_id(Integer[] anc_id) {
this.anc_id = anc_id;
}
public String Publish() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
list=ad.Query();
if(count!=0){
anc_id=new Integer[count];
for(int i=0;i<count;i++){
ad.Publis(anc_id[i], anc_who);
}
}
return SUCCESS;
}问题:anc_id在Action中的值为null.请高手指点!多谢!

解决方案 »

  1.   

    隐藏域应该是没办法存对象 比如你这里的数组
    放session里面吧
      

  2.   

    额我要传过去的并非一个数组对象。要穿过去的知识checkbox所选中的anc_id数组,所以在Action中也没有使用List来接收。
      

  3.   

    额说明下情况,同为隐藏域的count的值能传过去,而anc_id却传不过去,所以我认为我的问题是出在数组上(虽然我自己也不是完全确定)
      

  4.   

    <c:forEach var="list" items="${list}">
      <tr><td><input type="checkbox" name="publish" id="publish" value="${list.anc_id }"/></td>
      <td>${list.anc_title}</td>
      <td id="anc_content">${list.anc_content }
      </tr>
    </c:forEach>action中。  request.getParameterValues(“publish”)
      

  5.   

    检查看count是否放在表单里面,另外检查你的action里面count有没有提供setter getter。最后,你这种方法确实有点笨拙,你要获取checkbox的个数也不必使用这种办法吧,c:forEach...
       <input type="checkbox" name="chkItem" />比如你这里定义name为chkItem然后你action里面
    String[] items=request.getParameterValues("chkItem");得到一个数组
    通过items.length不好一些吗?
      

  6.   

    放到session额。不大明白具体要做怎么做,对于7楼,我的问题没有出在count,我知道你的方法,但是我要的并不是所有checkbox的数量,而是在里面再做选择,方法确实有点儿笨拙,不过,新手嘛,也没什么好方法,如果有更好的方法,希望多多指教
      

  7.   

    如果放在session里面不是还要存吗?存的时候还不是要用对象或者anc_id来接收吗?而问题不是恰恰出在jsp中anc_id数组的传递和Action的接收方面吗?
      

  8.   

    两次request.setAttrbuite 应该就可以了 在下个action中获得就可以了
      

  9.   

    囧,你的checkbox是不是不是一个
    但是你的每个checkbox的id都是publish吧,所以取值的时候不知道传的是哪个?
      

  10.   

    晕,我说错了,你传的那个anc_id在页面上有值么
      

  11.   

    必须的!有值。我后来把Action层得数组类型给改为int后,倒是能运行了,就是接收到得anc_id的值都为0.不知道什么情况
      

  12.   

    囧 ,你设置的是数组?看你的传值,你传的时候是anc_id这个参数,他的值是${list.anc_id }
    你在页面获取这个值是数组么?
      

  13.   

    在jsp中不知道是不是个数组,它是Action中传过去的list,然后在jsp中foreach中循环取得所有的anc_id
      

  14.   

    你还是看看anc_id的类型,然后再在action中获取
      

  15.   

    也是哦。那我把anc_id都换成int型试试。
      

  16.   

    恩。帅哥,我试了,连Model层得都改int了还不行。