复选框选中问题,权限问题
A页面,B页面,A页面有个按钮,单击A页面传一个uid到B页面,B页面有两个集合,
怎么把该用户有的权限的复选框选中,
<%
IUserDaoService userDaoServer = new UserDaoServerImpl();
int uid = Integer.parseInt(request.getParameter("uid"));//获得到用户的Id
List<Give> list = userDaoServer.findAdminPurviewByName(uid);//根据用户ID查询该用户的权限集合
List<Purview> listPurview = userDaoServer.findPurviewAll();//从数据库中循环读取权限
User user = userDaoServer.findUserByUid(uid); //查询该用户
%>
<body >
<form action="admin/doUpdate.jsp?updateId=<%=uid %>" method="post" name = "form" >
<div>用户名:<input type ="text" id ="username" value ="<%=user.getUserName() %>" readonly="readonly"></div>
<div>旧密码:<input type ="text" value ="<%=user.getPassword()%>"></div>
<div>新密码:<input type ="text" name = "newPass" ></div>
<div>确认密码:<input type ="text" id ="rpass" ></div>
<div>
<input type="radio" value="" name="k"/>
修改权限
<input type="radio" value="" name="k"/>
修改权限
</div>
<%
for(int i =0;i<listPurview.size();i++){
Purview pur = listPurview.get(i); //循环数据库中所有的权限
%>
<div id="enter_checkBox" >
<div ><%=pur.getNodeName()%>
<input name="index" type="checkbox" value="<%=pur.getNodeId() %>" /></div>
</div>
<%}
[解决办法]
如果list只是权限id这个字段,可以用下面的这个list.contains()方法来判断
<input name="index" type="checkbox" value="<%=pur.getNodeId() %>" <%if(list.contains(pur.getNodeId())){out.print("checked");}%> /></div>
如果list里面是个object,那就要循环listPurview里面再循环list,找到匹配的就out.print{("checked");}