checkbox的取值问题

likktank11 2004-08-24 05:36:59
String[] checkvalue=request.getParameterValues("delete");
System.out.println(checkvalue[0]);

输出显示值没有取到
这句取值语句有什么问题吗?
...全文
198 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
likktank11 2004-08-25
问题解决了 原来上一个</form>结束在了循环的里面
谢谢各位~~~
回复
hary90 2004-08-25
应该没有问题,你可以运行网页后在浏览器看看你的原代码,看是否与你设计相符?
回复
likktank11 2004-08-25
<input type=checkbox name=delete value="<%=custID%>"></th>
我怀疑是不是这个value值定义有问题? 请高手赐教~~
回复
likktank11 2004-08-25
<form name=delete action="/salesmanageWeb/DelCustServlet" method="Post" style="border-left-style: solid; border-left-width: 0; border-right-width: 1; border-top-width: 1; border-bottom-width: 1">
<tr align="left">
<th width="37" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<input type=checkbox name=delete value="<%=custID%>"></th>

我的input 在下面啊 是不是form的name和input的name不能重复?
这个我倒是疏忽没有注意
回复
bluesky35 2004-08-25
你把delete定义成了form,当然取不到
回复
likktank11 2004-08-25
这是网页的部分代码
<%
java.sql.Connection con = null;
java.sql.ResultSet rs = null;
com.db.database.DatabaseObject dbBean = new com.db.database.DatabaseObject();
int cu = 1;
String linkMan = "";
String custID = "";
String custName = "";
String Phone = "";
String Telecopy = "";
String Address = "";
String Color="#ffffff";
try{
dbBean.getConnection();
rs = dbBean.getResultSet("select custlinkman,custid,custname,custphone,custtelecopy,custadd from salescust where userid = "+ userId);
while(rs.next()){
if (cu % 2 == 0) { Color="#A0CFFE"; }
else { Color="#FFFFFF"; }
linkMan = rs.getString("CUSTLINKMAN");
custID = rs.getString("CUSTID");
custName = rs.getString("CUSTNAME");
Phone = rs.getString("CUSTPHONE");
Telecopy = rs.getString("CUSTTELECOPY");
Address = rs.getString("CUSTADD");
%>
</form>
<form name=delete action="/salesmanageWeb/DelCustServlet" method="Post" style="border-left-style: solid; border-left-width: 0; border-right-width: 1; border-top-width: 1; border-bottom-width: 1">
<tr align="left">
<th width="37" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<input type=checkbox name=delete value="<%=custID%>"></th>
<th width="86" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<p align="center"><a href="demand_cust2.jsp?id=<%=custID%>"><%=custID%></a></th>
<th width="174" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<%=custName%></th>
<th width="118" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<%=Phone%></th>
<th width="112" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<%=Telecopy%></th>
<th width="89" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<%=linkMan%></th>
<th width="206" style="color: black; font-size: 12px; font-weight: 400; background-color: <%=Color%>;" height="1">
<%=Address%></th>
</tr>
<%
cu++;
}
}
catch (Exception e){}
finally{
if (dbBean != null) {
dbBean.close();
}
}
%>

</table>

</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="774" height="55" id="AutoNumber4">
<tr>
<td width="774" height="55">
<p align="center">
<font face="宋体" style="font-size: 9pt; background-color:#FFFFFF"><input type="submit" value="删除" name="submit1"></font></td>
</tr>
</table>
</center>
</div>
</form>

</body>
<%@include file="bottom.jsp"%>
</html>
回复
gln 2004-08-24
是不是你的网页里的input标签中的name属性名没有设定好吧
回复
angelheart 2004-08-24
觉得你应该把网页代码给出来~~~你有没给checkbox定义value?
<input type="checkbox" name="delete" value="1">
回复
tomuno 2004-08-24
<input type="checkbox" name="delete">
回复
likktank11 2004-08-24
下面是我的整个SERVLET,高手看看有什么问题吗?小弟先谢了

package com.sales;

import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import com.db.database.DatabaseObject;



public class DelCustServlet
extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response) {
Connection con = null;
java.sql.ResultSet rs = null;
DatabaseObject dbBean = new DatabaseObject();
System.out.println("0");
try {
String[] checkvalue=request.getParameterValues("delete");
System.out.println(checkvalue[0]);
dbBean.getConnection();
dbBean.setAutoCommit(false);
for(int i=0;i< checkvalue.length;i++)
{
dbBean.getUpdateCount("delete from salescust where custid='" + checkvalue[i] + "'");
try {
dbBean.commit();
}
catch (Exception e) {
dbBean.rollback();
}
}
}
catch (Exception e) {
}
finally {
try {
if (dbBean != null) {
dbBean.close();
}
}
catch (Exception e) {}
}
}
}
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-08-24 05:36
社区公告
暂无公告