在做一个图书管理系统,在数据库中查询到一条书的记录后,我想要实现“删除”和“更新”两个操作。分别由href= "del.jsp和upd.jsp来实现。这需要把记录的“id”(主键)传给两个文件。于是我用了以下语句:
<td width= "30 " valign= "middle " align= "center "> <a href= "upd.jsp "? id=rs.getString( "id ")> 更新 </a> <a href= "del.jsp "? id=rs.getString( "id ")> 删除 </a> </td>
并且在两个文件里String id=request.getParameter( "id ");来获得id,可结果显示的却是null,这是怎么回事,还请各位大虾指教。
------解决方案--------------------
<a href= "del.jsp "? id=rs.getString( "id ")>
改成
<a href= "del.jsp? id= <%rs.getString( "id ")%> ">
------解决方案--------------------
<a href= "del.jsp "? id=rs.getString( "id ")>
改成
<a href= "del.jsp? id= <%rs.getString( "id ")%> ">
改成
<a href= 'del.jsp? id= <%=rs.getString( "id ")%> '>
------解决方案--------------------
<a href= "del.jsp "? id=rs.getString( "id ")> 有问题
应该写成 <a href= "del.jsp "? id= <%=rs.getString( "id ")%> >
或者定义从数据库得到的值:
String myid=rs.getString( "id ");
再
<a href= "del.jsp "? id=myid>
------解决方案--------------------
<%
id = rs.getString( "id ");
%>
<a href = "upd.jsp? <%=id%> ">
总的做法就是在 <a> 标签之前求出id值,然后用表达式。其实和楼上差不多。
------解决方案--------------------
刚刚来想看下得分,看见没得,实在郁闷,就看了下你那段长的代码,发现个大问题:
......
<%
while(rs.next()){
rowcount++;
id=rs.getString( "id "); /////这里已经取出了 "id "字段的值
name=rs.getString( "name ");
author=rs.getString( "author ");
price=rs.getFloat( "price ");
amount=rs.getLong( "amount ");
product=rs.getString( "product ");
type=rs.getString( "type ");
%>
<tr>
<td> <table border= "1 " width= "600 " heigth= "15 ">
<td width= "30 " valign= "middle " align= "center "> <%=id%> </td>
<td width= "30 " valign= "middle " align= "center "> <%=name%> </td>
<td width= "30 " valign= "middle " align= "center "> <%=author%> </td>
<td width= "30 " valign= "middle " align= "center "> <%=price%> </td>
<td width= "30 " valign= "middle " align= "center "> <%=amount%> </td>
<td width= "30 " valign= "middle " align= "center "> <%=product%> </td>
<td width= "30 " valign= "middle " align= "center "> <%=type%> </td>
<td width= "30 " valign= "middle " align= "center ">
<a href= "upd.jsp "? id=rs.getString( "id ")> 更新 </a> /// 所以这两句就不能在对
<a href= 'del.jsp? id= <%=rs.getString( "id ")%> '> 删除 </a> /// "id "取值了.
</td>
</table> </td> </tr>
<%
总的来讲,就是循环里的rs.get...( "字段 ")语句,字段值只能出现一次.