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.请高手指点!多谢!
<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.请高手指点!多谢!
放session里面吧
<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”)
<input type="checkbox" name="chkItem" />比如你这里定义name为chkItem然后你action里面
String[] items=request.getParameterValues("chkItem");得到一个数组
通过items.length不好一些吗?
但是你的每个checkbox的id都是publish吧,所以取值的时候不知道传的是哪个?
你在页面获取这个值是数组么?