jsp中由Action传来的list再传给Action

hdl17 2011-08-02 05:10:30
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.请高手指点!多谢!
...全文
394 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel 2011-08-03
  • 打赏
  • 举报
回复
囧,那你加我QQ:815648203
我看看~~
hdl17 2011-08-03
  • 打赏
  • 举报
回复
恩。帅哥,我试了,连Model层得都改int了还不行。
hdl17 2011-08-03
  • 打赏
  • 举报
回复
也是哦。那我把anc_id都换成int型试试。
angel 2011-08-03
  • 打赏
  • 举报
回复
你还是看看anc_id的类型,然后再在action中获取
hdl17 2011-08-03
  • 打赏
  • 举报
回复
在jsp中不知道是不是个数组,它是Action中传过去的list,然后在jsp中foreach中循环取得所有的anc_id
angel 2011-08-03
  • 打赏
  • 举报
回复
囧 ,你设置的是数组?看你的传值,你传的时候是anc_id这个参数,他的值是${list.anc_id }
你在页面获取这个值是数组么?
hdl17 2011-08-03
  • 打赏
  • 举报
回复
之前是 Integer anc_id[];
angel 2011-08-03
  • 打赏
  • 举报
回复
额,你之前是什么类型的?
hdl17 2011-08-03
  • 打赏
  • 举报
回复
必须的!有值。我后来把Action层得数组类型给改为int后,倒是能运行了,就是接收到得anc_id的值都为0.不知道什么情况。。。
angel 2011-08-03
  • 打赏
  • 举报
回复
晕,我说错了,你传的那个anc_id在页面上有值么
angel 2011-08-03
  • 打赏
  • 举报
回复
囧,你的checkbox是不是不是一个
但是你的每个checkbox的id都是publish吧,所以取值的时候不知道传的是哪个?
飓风zj 2011-08-03
  • 打赏
  • 举报
回复
两次request.setAttrbuite 应该就可以了 在下个action中获得就可以了
hdl17 2011-08-03
  • 打赏
  • 举报
回复
如果放在session里面不是还要存吗?存的时候还不是要用对象或者anc_id来接收吗?而问题不是恰恰出在jsp中anc_id数组的传递和Action的接收方面吗?
hdl17 2011-08-03
  • 打赏
  • 举报
回复
放到session。。。额。不大明白具体要做怎么做,对于7楼,我的问题没有出在count,我知道你的方法,但是我要的并不是所有checkbox的数量,而是在里面再做选择,方法确实有点儿笨拙,不过,新手嘛,也没什么好方法,如果有更好的方法,希望多多指教。。。
DavidChou 2011-08-02
  • 打赏
  • 举报
回复
检查看count是否放在表单里面,另外检查你的action里面count有没有提供setter getter。

最后,你这种方法确实有点笨拙,你要获取checkbox的个数也不必使用这种办法吧,

c:forEach...
<input type="checkbox" name="chkItem" />比如你这里定义name为chkItem



然后你action里面
String[] items=request.getParameterValues("chkItem");得到一个数组
通过items.length不好一些吗?
JavaBoyCaoJi 2011-08-02
  • 打赏
  • 举报
回复
你把对象放到form里面看看,
皮皮 2011-08-02
  • 打赏
  • 举报
回复
<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”)
五哥 2011-08-02
  • 打赏
  • 举报
回复
放到session中
hdl17 2011-08-02
  • 打赏
  • 举报
回复
额。。。说明下情况,同为隐藏域的count的值能传过去,而anc_id却传不过去,所以我认为我的问题是出在数组上(虽然我自己也不是完全确定)
hdl17 2011-08-02
  • 打赏
  • 举报
回复
额。。。我要传过去的并非一个数组对象。要穿过去的知识checkbox所选中的anc_id数组,所以在Action中也没有使用List来接收。
加载更多回复(1)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧