还是这个问题,谁答对了给谁分

xiaoyue_yu 2002-04-09 03:36:35
问题:我把strChoice.equals("delete")等换成"删除","编辑","增加".当然提交钮的value也换成这三个了。为什么汇报错?求解决之道

<%@ page import="java.sql.*,ConnectDB,java.lang.String,java.util.ArrayList" contentType="text/html; charset=gb2312" %>
<jsp:useBean id="conn" scope="page" class="ConnectDB" />
<%@ include file="include.jsp"%>
<html>
<head>
<title>right</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../../include/css/main.css" type="text/css">
</head>
<script language="javascript">
function checkNum()
{
var nCount=0
for(var i=0;i<form1.checkbox.length;i++)
{
if (form1.checkbox[i].checked) nCount= nCount + 1;
}
if (nCount==0 || nCount>1)
{
alert("你只能选择一条而且只能选择一条");
return false;
}
else
return true;
}
</script>
<%
// ArrayList arrayCat=new ArrayList();
// String sql="select syscatno,syscatname from WL_ES_Syscat";
// out.println(sql);
// ResultSet rs=conn.query(sql);
// while(rs.next())
// {
// arrayCat.add(new Integer(rs.getInt("syscatno")));
// arrayCat.add(rs.getString("syscatname"));
// }
// rs.close();

// for(int i=0;i<arrayCat.size();i++)
// {
// out.println(arrayCat.get(i));
// }
%>
<%
if (request.getParameter("tijiao")!=null)
{
String strChoice=request.getParameter("tijiao");
if (strChoice.equals("delete"))
{
String check[]=request.getParameterValues("checkbox");
//if (arrSelList!=null)
//int nSelListNum=arrSelList.length;
if(check!=null)
{
for(int i=0;i<check.length;i++)
{
String sql2="delete from WL_ES_Syscat where SyscatNo=" + check[i];
conn.execute(sql2);
//out.println(sql2);
}
}
}

else if (strChoice.equals("add"))

response.sendRedirect("/WL/ES/SysCatadd.jsp");
else if (strChoice.equals("edit"))
{
String strMyNo=request.getParameter("checkbox");
response.sendRedirect("/WL/ES/SysCatedit.jsp?strNo=" + strMyNo);
}
%>

<%

}

//Get category from database
String strMySql="select * from WL_ES_SysCat";
ResultSet objMyRs=conn.query(strMySql);

%>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<form method="post" name="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="800">
<tr>
<td bgcolor="8FD5E2" align="center" valign="top">
<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center" height="19">
<tr>
<td bgcolor="F8EEC0" width="41.5%">
<div align="center"><a href="xxx.html">制度查阅</a></div>
</td>
<td bgcolor="F8EEC0" width="41.5%">
<div align="center"><a href="SysManage.jsp">制度管理</a> </div>
</td>
</tr>
</table>
<table width="98%" border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td align="center" valign="top" width="83%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top" width="100%">
<TABLE cellSpacing=0 cellPadding=8 width="100%" border=0>
<TR>

<TD vAlign=top align=left>
<p>
<input type="button" name="Submit" value="制度类别" onClick="javascript:window.location='SysManage.jsp'">
<input type="button" name="Submit2" value="制度维护" onClick="javascript:window.location='SysAdmin.jsp'">
</p>
<br>
<table width="75%" border="1">
<tr>
<td><div align="center">标示</div></td>
<td><div align="center">类别名称</div></td>
</tr>
<%
while(objMyRs.next())
{
String strCatName=objMyRs.getString("SyscatName");
%>
<tr>
<td>
<input type="checkbox" name="checkbox" value="<%=objMyRs.getInt("SyscatNO")%>">
</td>
<td><div align="center"><%=strCatName%></div></td>
</tr>
<%
}
objMyRs.close();
%>
</table>
<p><SPAN class=tt2><span class=tt2><span class=tt2><span class=tt2><span class=tt2><br>
<input type="submit" name="tijiao" value="add">
<input type="submit" name="tijiao" value="edit" onclick="return checkNum()">
<input type="submit" name="tijiao" value="delete">
</span></span> </span> </span></SPAN> </p>
</TD>
</TR>
</TABLE>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td bgcolor="6FC9DA" width="26"> </td>
</tr>
</table>
</form>
</body>
</html>

...全文
69 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
可乐加水 2002-04-09

我做了如下的修改:
if (strChoice.equals("delete"))
改成if (strChoice.equals("删除"))
else if (strChoice.equals("add"))
改成else if (strChoice.equals("添加"))
else if (strChoice.equals("edit"))
改成else if (strChoice.equals("编辑"))
<input type="submit" name="tijiao" value="add">
改成<input type="submit" name="tijiao" value="添加">
<input type="submit" name="tijiao" value="edit" onclick="return checkNum()">
改成<input type="submit" name="tijiao" value="编辑" onclick="return checkNum()">
<input type="submit" name="tijiao" value="delete">
改成<input type="submit" name="tijiao" value="删除">
结果运行的时候再这几个判断的地方绝对没有出现错误!你再试一次


回复
xiaoyue_yu 2002-04-09
靠意思都没搞东
回复
scarab 2002-04-09
是这个意思吗?
如果不是,那就对不起了
回复
scarab 2002-04-09
<input type="submit" name="tijiao" value="add">
<input type="submit" name="tijiao" value="edit" onclick="return checkNum()">
<input type="submit" name="tijiao" value="delete">

有错误
应该取不同的name
<input type="submit" name="add" value="add">
<input type="submit" name="tijiao" value="edit" onclick="return checkNum()">
<input type="submit" name="delete" value="delete">

然后你通过
if (request.getParameter("tijiao")!=null)
if (request.getParameter("add")!=null)
if (request.getParameter("delete")!=null)
来判断点击的是哪个
回复
scarab 2002-04-09
什么错误?
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告