我有一个页面,进入这个页面之后,显示一个 <table>会显示数据库中人员表中的所有用户信息 每个用户占一行,在每一行的最后一个字段,是删除字段,我现在在这里写的是超链接,通过拼字符串的方式 把一个用户的用户名(用户名唯一)传到执行删除操作的页面执行相应的操作 ,删除操作的页面没用任何内容显示,请高手看看现将页面的代码置下:链接页面:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="conn.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户管理</title>
</head><body bgcolor="#cad7f7">
<% Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users ";
ResultSet rs=stmt.executeQuery(sql);
if(rs!=null)
{
%>
<p> </p>
<table width="58%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolorlight="#145aa0"
bordercolordark="#9cc7ef">
<tr>
<th width="270" height="28" align="center" bgcolor="#4296e7"><font color="#FFFFFF">用户管理</font></th>
<td align="center" height="28" colspan="2" bgcolor="#4296e7"> </td>
</tr>
<tr bgcolor="#5ea5e6">
<td align="left" bgcolor="#5ea5e6">用户姓名</font></td>
<td colspan="2" align="center" bgcolor="#5ea5e6"><font color="ffffff">操作</font></td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td align="center" bgcolor="#88ccff"><%=rs.getObject("name")%></td>
<td width="63" align="center" bgcolor="#88ccff">
<a href="modiuser.jsp?oldname="<%=rs.getObject("name")%>>修改</a></td>
<td width="73" align="center" bgcolor="#88ccff">
<a href="deluser.jsp?delname="<%=rs.getObject("name")%>>删除</a></td>
<%
}
%>
<tr bgcolor="#4296e7">
<td align="center"> </td>
<td colspan="2" align="center"><a href="adduser.jsp"><font color="#FFFF00">新增用户</font></a></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>执行删除页面:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="conn.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>删除用户</title>
</head><body bgcolor="#cad7f7">
<h2 align="center">删除用户</h2>
<hr>
<%
String msg=null;
String name=request.getParameter("delname");
if(name!=null)
{
if(name.equals(""))
{
msg="用户名不能为空!";
}
else
{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="DELETE FROM users where name='"+name+"'";
stmt.executeUpdate(sql);
int n=stmt.executeUpdate(sql);
if(n==0)
{
msg="用户名或密码错误!";
response.sendRedirect("manageuser.jsp?msg="+msg);
}
stmt.close();
conn.close();
}
}
%>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="conn.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户管理</title>
</head><body bgcolor="#cad7f7">
<% Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users ";
ResultSet rs=stmt.executeQuery(sql);
if(rs!=null)
{
%>
<p> </p>
<table width="58%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolorlight="#145aa0"
bordercolordark="#9cc7ef">
<tr>
<th width="270" height="28" align="center" bgcolor="#4296e7"><font color="#FFFFFF">用户管理</font></th>
<td align="center" height="28" colspan="2" bgcolor="#4296e7"> </td>
</tr>
<tr bgcolor="#5ea5e6">
<td align="left" bgcolor="#5ea5e6">用户姓名</font></td>
<td colspan="2" align="center" bgcolor="#5ea5e6"><font color="ffffff">操作</font></td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td align="center" bgcolor="#88ccff"><%=rs.getObject("name")%></td>
<td width="63" align="center" bgcolor="#88ccff">
<a href="modiuser.jsp?oldname="<%=rs.getObject("name")%>>修改</a></td>
<td width="73" align="center" bgcolor="#88ccff">
<a href="deluser.jsp?delname="<%=rs.getObject("name")%>>删除</a></td>
<%
}
%>
<tr bgcolor="#4296e7">
<td align="center"> </td>
<td colspan="2" align="center"><a href="adduser.jsp"><font color="#FFFF00">新增用户</font></a></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>执行删除页面:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="conn.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>删除用户</title>
</head><body bgcolor="#cad7f7">
<h2 align="center">删除用户</h2>
<hr>
<%
String msg=null;
String name=request.getParameter("delname");
if(name!=null)
{
if(name.equals(""))
{
msg="用户名不能为空!";
}
else
{
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="DELETE FROM users where name='"+name+"'";
stmt.executeUpdate(sql);
int n=stmt.executeUpdate(sql);
if(n==0)
{
msg="用户名或密码错误!";
response.sendRedirect("manageuser.jsp?msg="+msg);
}
stmt.close();
conn.close();
}
}
%>
</body>
</html>
<td width="63" align="center" bgcolor="#88ccff">
<a href="modiuser.jsp?oldname=" <%=rs.getObject("name")%>>修改 </a> </td>
<td width="73" align="center" bgcolor="#88ccff">
<a href="deluser.jsp?delname=" <%=rs.getObject("name")%>>删除 </a> </td>
LZ这几行代码有问题 传参数错误
因该<a href="deluser.jsp?delname=<%=rs.getObject('name')%>" >删除 </a> </td>
设置下,添加2句
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");======================================================
最好不要根据姓名来删除,建议用id去删除用户。。
如果是同名的话,就有可能删掉多条用户信息。id是唯一的,删除时,只能删除一条记录。。
String str=request.getParameter("delname");
String name=new String(str.getBytes("iso-8859-1"),"GBK");
这样name就不是乱码了
String delname=request.getParameter("delname");
String name=new String(delname.getBytes("iso-8859-1"),"GBK");