救急!jsp中复选框的问题

wl7777777 2004-09-16 03:52:35
请看代码
<logic:iterate>
<html:multibox property="selectedItems"><bean:write name="View" property="FFuncno" /></html:multibox>
</logic:iterate>

我用<html:multibox></html:multibox>标签把选中的FFuncno在数据库中作了标识,开始所有的FFuncno都在数据库中。
然后我想从数据库中取出所有的FFuncno(选中和没有选中的)并且在页面上开始选中的那些FFuncno所对应的复选框要显示被选中状态。
太怎样做啊,哪位大虾帮忙。。。
谢谢!!
...全文
161 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vision2000 2004-09-20
  • 打赏
  • 举报
回复
up
xunyiren 2004-09-18
  • 打赏
  • 举报
回复
周末放假,家里又没有开发环境,随手写了一些代码,不太完整,希望对你能有些帮助:(
xunyiren 2004-09-18
  • 打赏
  • 举报
回复
1.假设显示页面对应的ActionForm名为EnterpriseForm,它应有以下代码:
private String[] fFuncno=null;
public void setFFuncno(String[] s) {
fFuncno=s;
}
public String[] getFFuncno() {
return fFuncno;
}
用于循环输出所有的FFuncno的Bean类A,应有以下代码:
private String fFuncno=null;
private String fFname=null;
public void setFFuncno(String s) {
fFuncno=s;
}
public String getFFuncno() {
return fFuncno;
}
public void setFFname(String name) {
fFname=name;
}
public String getFFname() {
return fFname;
}
2.Action:
..................
EnterpriseForm er = new EnterpriseForm();
A beanA = new A();
ArrayList list= new ArrayList();
String sql = "select FFuncno,FFname from yourtable";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
beanA.setFFuncno(rs.getString("FFuncno"));
beanA.setFFuncno(rs.getString("FFname"));
list.add(beanA);
}
......................
sql = "select count(*) from yourtable where 条件";
rs = stmt.executeQuery(sql);
rs.next();
String[] strArray=new String[rs.getInt(1)];
sql = "select FFuncno,FFname from yourtable where 条件";(取出选中的)
rs = stmt.executeQuery(sql);
int i=0;
while (rs.next()) {
strArray[i]=rs.getString("FFuncno");
i++;
}
er.setFFuncno(strArray);
......................
request.setAttribute("er_list",list);
request.setAttribute("enterpriseForm",er);

return mapping.findForward("success");
3.显示页面,注意该页面所对应的<form-bena>的名字为enterpriseForm.
<logic:present name="er_list" scope="request">
<tr>
<logic:iterate name="er_list" id="list" scope="request">
<td height="25">
<html:multibox property="fFuncno"><bean:write name="list" property="fFuncno"/></html:multibox>
<bean:write name="list" property="fFname"/>
</td>
<bean:define id="divideRow" value="<%=String.valueOf(++index%4)%>"></bean:define>
<logic:equal name="divideRow" value="0"></tr><tr></logic:equal>
</logic:iterate>
</logic:present>
wl7777777 2004-09-18
  • 打赏
  • 举报
回复
还是有些模糊,这位大哥能不能把action的内容贴出来我详细的理解一下,因为关系到很多实现的细节,比如说一个表中同一字段要取两次。。。
xunyiren 2004-09-16
  • 打赏
  • 举报
回复
1.在Action中从数据库中取出所有的FFuncno(选中和没有选中的)集合(ArrayList)放到Bean A里(scope:request或session).
2.在Action中从数据库中取出选中的FFuncno,setter到显示页面对应的ActionForm的String[]属性中,把该ActionForm放到Bean B里(scope:request或session).
3.显示页面类似这样:
循环输出Bean A,jsp容器会利用标签把页面checkbox值存在于Bean B String[]属性中的复选框选中.(我每一行输入四个checkbox)
<logic:present name="er_list" scope="session">
<tr>
<logic:iterate name="er_list" id="list" scope="session">
<td height="25">
<html:multibox property="erid"><bean:write name="list" property="erid"/></html:multibox>
<bean:write name="list" property="cname"/>
</td>
<bean:define id="divideRow" value="<%=String.valueOf(++index%4)%>"></bean:define>
<logic:equal name="divideRow" value="0"></tr><tr></logic:equal>
</logic:iterate>
</logic:present>
gumplei 2004-09-16
  • 打赏
  • 举报
回复
up...

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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