从后台servlet中,获取jsp页面输入的值,来删除用户一行信息
后台servlet设置
protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
string method=request.getparameter("method");
string id=request.getparameter("u_id");
system.out.println("id="+id);
//int u_id=integer.valueof(id);
if("displayuser".equals(method)){
list<user> usermessage=userservice.displayuser();
request.setattribute("list_usermessage", usermessage);
request.getrequestdispatcher("usermessage.jsp").forward(request, response);
}
if("deleteuser".equals(method)){
boolean flag=userservice.deleteuser(integer.valueof(id));
if(flag){
list<user> usermessage=userservice.displayuser();
request.setattribute("list_usermessage", usermessage);
request.getrequestdispatcher("usermessage.jsp").forward(request, response);
}else{
response.getwriter().println("<script>alert(\"删除失败!\");</script>") ;
}
}
}
jsp页面设置
方式一:表单提交(隐藏表单域技术)
<form action="usermesgservlet?method=deleteuser" method="post">
<table border="0"cellspacing="0" cellpadding="0">
<tr>
<td style="width:50px;text-align: center">序号</td>
<td style="width:150px;text-align: center">用户名</td>
<td style="width:200px;text-align: center">密码</td>
<td style="width:200px;text-align: center">邮箱号</td>
<td style="width:200px;text-align: center">手机号</td>
<td style="width:100px;text-align: center">操作</td>
</tr>
<c:foreach items="${list_usermessage}" var="user" varstatus="i">
<tr style="background:#7fffd4">
<td style="width:50px;text-align: center">${i.count} </td>
<input type="hidden" name="c_id" id="c_id" value="${user.u_id} ">
<td style="width:100px;text-align: center">${user.u_name}</td>
<td style="text-align: center"><font style="font-size:12px;">${user.u_password}</font></td>
<td style="text-align: center">${user.u_email}</td>
<td style="width:100px;text-align: center">${user.u_phone}</td>
<td style="text-align: center"><input type="submit" value="删除"></td>
</tr>
</c:foreach>
</table>
方式二:超链接提交(传递参数要参数进行拼接)
<table border="0"cellspacing="0" cellpadding="0">
<tr>
<td style="width:50px;text-align: center">序号</td>
<td style="width:150px;text-align: center">用户名</td>
<td style="width:200px;text-align: center">密码</td>
<td style="width:200px;text-align: center">邮箱号</td>
<td style="width:200px;text-align: center">手机号</td>
<td style="width:100px;text-align: center">操作</td>
</tr>
<c:foreach items="${list_usermessage}" var="user" varstatus="i">
<tr style="background:#7fffd4">
<td style="width:50px;text-align: center">${i.count} </td>
<td style="width:100px;text-align: center">${user.u_name}</td>
<td style="text-align: center"><font style="font-size:12px;">${user.u_password}</font></td>
<td style="text-align: center">${user.u_email}</td>
<td style="width:100px;text-align: center">${user.u_phone}</td>
<td style="text-align: center"><a href="usermesgservlet?method=deleteuser&u_id=${user.u_id}" target="middle">删除</a></td>
</tr>
</c:foreach>
</table>
上一篇: kmp算法