jsp 做删除功能时如何将id值传递给按钮
如图所示我想实现的功能是选中列表中单选框,然后点击删除单位信息按钮,就删除本条记录。如何将单选框的值传递给删除按钮?<%@pagelanguage="java"impor...
如图所示 我想实现的功能是选中列表中单选框,然后点击删除单位信息按钮,就删除本条记录。如何将单选框的值传递给删除按钮?
<%@ page language="java" import="java.util.*,com.bean.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'displaydw.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="">
<script type="text/javascript">
fucntion getInfo(){
var text = document.getElementById("selradio").value;
var action = "deletedwdo.jsp?id="+text;
window.location=action;
}
</script>
<big><strong>单位信息</strong></big> <br />
<hr />
<form id="form1" name="form1" action="dw/updatedw.jsp" method="post" target="mainFrame">
<table width="100%" border="1">
<tr>
<th>编号</th><th>单位编号</th><th>单位名称</th><th>工商执照号码</th><th>组织机构代码</th>
</tr>
<%
List lstbc =(List)request.getAttribute("lstbc");
int sum=0;
if(lstbc!=null){
sum=lstbc.size();
Iterator it=lstbc.iterator();
while(it.hasNext()){
Dwjbxx tempbc=(Dwjbxx)it.next();
%>
<tr>
<td align="center"><input type='radio' id="selradio" name="selradio" value=<%= tempbc.getId()%> checked="checked" /></td>
<td align="center"><%= tempbc.getDwbh()%></td>
<td align="center"><%= tempbc.getDwmc()%></td>
<td align="center"><%= tempbc.getGsdjzzhm()%></td>
<td align="center"><%= tempbc.getZzjgdm()%></td>
</tr>
<%
}
}
%>
</table>
<table>
<tr>
<th align="center" ><input type="submit" value="修改单位信息" /></th>
<th align="center" ><input type="button" value="删除单位信息" onclick="getInfo()"></th>
</tr>
</table>
</form>
</body>
</html>
我用JS传的时候取不到 展开
<%@ page language="java" import="java.util.*,com.bean.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'displaydw.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="">
<script type="text/javascript">
fucntion getInfo(){
var text = document.getElementById("selradio").value;
var action = "deletedwdo.jsp?id="+text;
window.location=action;
}
</script>
<big><strong>单位信息</strong></big> <br />
<hr />
<form id="form1" name="form1" action="dw/updatedw.jsp" method="post" target="mainFrame">
<table width="100%" border="1">
<tr>
<th>编号</th><th>单位编号</th><th>单位名称</th><th>工商执照号码</th><th>组织机构代码</th>
</tr>
<%
List lstbc =(List)request.getAttribute("lstbc");
int sum=0;
if(lstbc!=null){
sum=lstbc.size();
Iterator it=lstbc.iterator();
while(it.hasNext()){
Dwjbxx tempbc=(Dwjbxx)it.next();
%>
<tr>
<td align="center"><input type='radio' id="selradio" name="selradio" value=<%= tempbc.getId()%> checked="checked" /></td>
<td align="center"><%= tempbc.getDwbh()%></td>
<td align="center"><%= tempbc.getDwmc()%></td>
<td align="center"><%= tempbc.getGsdjzzhm()%></td>
<td align="center"><%= tempbc.getZzjgdm()%></td>
</tr>
<%
}
}
%>
</table>
<table>
<tr>
<th align="center" ><input type="submit" value="修改单位信息" /></th>
<th align="center" ><input type="button" value="删除单位信息" onclick="getInfo()"></th>
</tr>
</table>
</form>
</body>
</html>
我用JS传的时候取不到 展开
展开全部
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*,com.study.project01.*"%>
<html>
<head>
<title>公告管理</title>
<style type="text/css">
body table{
font-size:12px;
}
.title{
font-family: Times;
font-size:19px;
font-weight:bold;
line-height:50px;
}
.td1{
background:url("img/bg2.jpg") repeat;
height:30px;
color:#8B008B;
}
</style>
</head>
<body>
<%
Connection conn = null; //将公告基本信息从数据库读出,并显示在页面上供选择处理
Statement sm = null;
ResultSet rs = null;
String sql = "select * from gonggaoinfo";
conn = DB.getConn();
sm = DB.createStmt(conn);
rs = DB.executeQuery(sm,sql);
%>
<%
request.setCharacterEncoding("gb2312");
String action = request.getParameter("action");
if(action != null && action.trim().equals("post")) {
String selected = request.getParameter("selected");
PreparedStatement psm = null;
String sql1 = "delete from gonggaoinfo where gonggaoid = '"+selected+"'";
conn = DB.getConn();
psm = DB.prepareStmt(conn,sql1);
psm.executeUpdate();
psm.close();
}
%>
<form action="gonggaodeal.jsp" method="post" name="form">
<input type="hidden" name="action" value="post" />
<div class="title">公告管理</div>
<table width="770px" border="3px">
<tr>
<td class="td1" width="33%" align="center">公告ID</td>
<td class="td1" width="33%" align="center">公告标题</td>
<td class="td1" width="33%" align="center">选择操作</td>
</tr>
<%
while(rs.next()) {
String gonggaoid = rs.getString("gonggaoid");
String gonggaotitle = rs.getString("gonggaotitle");
%>
<tr>
<td width="33%" align="center"><%=gonggaoid%></td>
<td width="33%" align="center"><%=gonggaotitle%></td>
<td width="33%" align="center"><input type="checkbox" name="selected" value=<%=gonggaoid%> /></td>
</tr>
<%
}
%>
<tr>
<td colspan=1 align="center"><input type="submit" value="删除"/></td>
<td colspan=2 align="center"><input type="button" value="更新" onclick="window.location.reload('gonggaodeal.jsp')" /></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page import="java.sql.*,com.study.project01.*"%>
<html>
<head>
<title>公告管理</title>
<style type="text/css">
body table{
font-size:12px;
}
.title{
font-family: Times;
font-size:19px;
font-weight:bold;
line-height:50px;
}
.td1{
background:url("img/bg2.jpg") repeat;
height:30px;
color:#8B008B;
}
</style>
</head>
<body>
<%
Connection conn = null; //将公告基本信息从数据库读出,并显示在页面上供选择处理
Statement sm = null;
ResultSet rs = null;
String sql = "select * from gonggaoinfo";
conn = DB.getConn();
sm = DB.createStmt(conn);
rs = DB.executeQuery(sm,sql);
%>
<%
request.setCharacterEncoding("gb2312");
String action = request.getParameter("action");
if(action != null && action.trim().equals("post")) {
String selected = request.getParameter("selected");
PreparedStatement psm = null;
String sql1 = "delete from gonggaoinfo where gonggaoid = '"+selected+"'";
conn = DB.getConn();
psm = DB.prepareStmt(conn,sql1);
psm.executeUpdate();
psm.close();
}
%>
<form action="gonggaodeal.jsp" method="post" name="form">
<input type="hidden" name="action" value="post" />
<div class="title">公告管理</div>
<table width="770px" border="3px">
<tr>
<td class="td1" width="33%" align="center">公告ID</td>
<td class="td1" width="33%" align="center">公告标题</td>
<td class="td1" width="33%" align="center">选择操作</td>
</tr>
<%
while(rs.next()) {
String gonggaoid = rs.getString("gonggaoid");
String gonggaotitle = rs.getString("gonggaotitle");
%>
<tr>
<td width="33%" align="center"><%=gonggaoid%></td>
<td width="33%" align="center"><%=gonggaotitle%></td>
<td width="33%" align="center"><input type="checkbox" name="selected" value=<%=gonggaoid%> /></td>
</tr>
<%
}
%>
<tr>
<td colspan=1 align="center"><input type="submit" value="删除"/></td>
<td colspan=2 align="center"><input type="button" value="更新" onclick="window.location.reload('gonggaodeal.jsp')" /></td>
</tr>
</table>
</form>
</body>
</html>
展开全部
取值的页面发来看看。
你的JS取值应该是没什么问题的,你可以在js里加个alert(text);测试下。
我估计是你的updatedw.jsp页面取值的时候,用的name值的问题,你的FORM的action的name值为:selradio,但JS里的为:id
你的JS取值应该是没什么问题的,你可以在js里加个alert(text);测试下。
我估计是你的updatedw.jsp页面取值的时候,用的name值的问题,你的FORM的action的name值为:selradio,但JS里的为:id
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
为什么要传给删除按钮呢?直接传入后台在数据库里删除此条记录不就OK了么?删除按钮提交表单
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询