1。当地址为href="/myRegister/myRegister.do?method=listRegister&&size=10&&&start=5"
可以通过下面方法分别取到size&&start:
Map requestMap = request.getParameterMap();
String size = requestMap.get("size");
String start =requestMap.get("start");
2。checkbox取相同名字,则表单上得到的是一个数组。
<tr>
<td><input type="checkbox" value="<%=register.getId()%>" id="id"/></td>
<td><%=register.getName()%></td>
<td><%=register.getPassword()%></td>
</tr>
问题一:表单提交以后,form的对象是什么??
问题二:如何利用request取到id的值数组??
问题二的解决方法为将id值用","连成字符串,将字符串传递给action以后再进行分解.具体的解决为:(实现批量删除)
delete.jsp:
<%@page import="com.xindeco.core.pagination.PaginationSupport" %>
<%@page import="com.xindeco.myregister.pojo.MyRegisterInfo"%>
<%
PaginationSupport support = (PaginationSupport)request.getAttribute("registerList");
List registerList=support.getItems();
%>
<script>
function concatValue(obj,delimiter) {//将id用,串成string
if(!obj) {
return false;
}
if(!obj.length&&obj.checked) {
return obj.value;
}
var str='';
for(var i=0;i<obj.length;i++) {
if(obj[i].checked) {
str=str+obj[i].value;
str=str+delimiter;
}
}
if(str.length>0) {
return str.substring(0,str.length-1);
}
return str;
}
function dele(obj)
{
var str = concatValue(obj,',');
location.href('/myRegister/myRegister.do? method=deleteRegister&&ids='+str);
}
</script>
<html ><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form action="/myRegister/myRegister.do?method=listRegister">
<table id="detailTable" width="100%" border="0" >
<tr>
<td></td> <td>姓名</td><td>password</td>
</tr>
<%
for(int i=0;i<registerList.size();i++)
{
MyRegisterInfo register= (MyRegisterInfo) registerList.get(i);
%>
<tr>
<td><input type="checkbox" value="<%=register.getId()%>" id="id"/></td>
<td><%=register.getName()%></td>
<td><%=register.getPassword()%></td>
</tr>
<% }%>
<tr><td><input type = "button" onclick="dele(document.getElementsByName('id'))" value="删除"></input></td></tr>
</table>
</form>
</body>
</html>
action中的方法:
String ids = req.getParameter("ids");
String[] idList = ids.split(",");
if(idList!=null){
Long[] idLong = new Long[idList.length];
for (int i = 0; i < idList.length; i++) {
idLong[i] = Long.valueOf(idList[i]);
}
if(service.deleteRegister(idLong)) return mapping.findForward("success");
}
其中deleteRegister的方法体为:
public boolean deleteRegister(Long[] ids)
{
MyRegisterDAO dao = (MyRegisterDAO) this.getBaseDAO();
for(int i=0;i<ids.length;i++) {
dao.remove(MyRegisterInfo.class,ids[i]);
}
return true;
}
dao.remove的方体为
public void remove(Class clazz, Serializable id) {
getHibernateTemplate().delete(get(clazz, id));
}
在这过程中我发现了long和Long的最大差别:Long是serializable类型,并且从string转化的过程也不同.
long simple = Long.ParseLong(str);
Long objLong = Long.valueOf(str);
posted on 2006-04-15 15:34
aimy 阅读(139)
评论(0) 编辑 收藏