checkbox的取值问题

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

输出显示值没有取到
这句取值语句有什么问题吗?
...全文
261 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
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) {}
}
}
}

81,122

社区成员

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

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