当前位置:编程学习 > JSP >>

jsp 复选框使用方法

答案:1,页面上
复制代码 代码如下:

<td width="4%" height="26" align="center">
<input type="checkbox" name="checkbox"
value=<%=user.getId()%> />
</td>


2.action
复制代码 代码如下:

String[] checkbox = request.getParameterValues("checkbox");
List<Integer> checkboxs = new ArrayList<Integer>();
int operatorId =SessionMgr.getAccountSession(request, response).getId();
logger.debug("--operatorId--:"+operatorId);
//判断复选框是否有选
if(checkbox!=null&&!"".equals(checkbox)){
for(int i=0;i<checkbox.length;i++){
//checkboxs.add(checkbox[i]);
String id_str = checkbox[i];
int id = Integer.parseInt(id_str);
//判断是否是自己本身
if(id==operatorId){
message="不能删除自己的用户";
}
//判断是否是admin超级管理员
if(id==1){
message="admin用户不能删除";
}
//判断该用户是否存在工单
boolean isExist= false;
isExist = UserMgr.isExistWorkbillOfUser(id);
logger.debug("--isExist--:"+isExist);
if(isExist){
message = "该用户有建工单不能删除";
}
if(id!=operatorId&&id!=1&&!isExist){
checkboxs.add(id);
}
}
try{
UserMgr.deleteUser(checkboxs);
message = "删除成功!";
}catch(SystemException se){
logger.error(se);
}
}
else{
message = "您还没选择用户!";
}

上一个:java 中文字符串数组按照音序排列
下一个:jsp网站永久换域名的处理过程

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,