关于用JSP显示数据库中商品详细信息的问题,急求各位高人指点,不胜感激
我做了个商品浏览页面,第一个页面列表显示数据库里面商品列表信息,然后在每条的缩略图上设置链接到另一个页面,显示该商品的详细信息。连数据库的时候不知道应该怎么办,显示商品详细信息的页面只出了个空表格,没有数据库里的东西。我的代码如下,希望各位指点一下:
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<jsp:useBean id= "databean " scope= "session " class= "com.conndb "/>
<jsp:useBean id= "list " class= "com.WaresList " scope= "session " />
<jsp:useBean id= "pagebean " scope= "session " class= "com.pagebean "/>
<html>
<head>
<title> 商品详细信息 </title>
<style type= "text/css ">
</style>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 "> </head>
<script language= "javascript ">
</script>
<body>
<div align= "center " class= "b9b "> 商品详细信息
<p>
<form action= "shopcart.jsp " method= "post " name= "form1 ">
<%
databean.getConnection();
ResultSet rs;
String sql= "SELECT * FROM wares ";
rs=databean.executeQuery(sql); //执行sql语句,使用了javabean conndb中的executeQuery
%>
<input type=hidden name= "id " value= " <%=list.WaresId%> " >
<table width= "300 " border= "1 " cellspacing= "1 " cellpadding= "1 " bordercolordark= "#6699ff " bordercolorlight= "#FFFFFF ">
<tr>
<th colspan= "2 " scope= "col "> <img src= "image/BigImg/ <%= list.BigImg %> "> </th>
</tr>
<tr>
<th width= "65 " scope= "row "> 商品名称 </th>
<th width= "222 " scope= "row "> <%=list.Name %> </th>
</tr>
<tr>
<th scope= "row "> 所属种类 </th>
<th scope= "row "> <%=list.Sort%> </th>
</tr>
<tr>
<th scope= "row "> 市场价 </th>
<th scope= "row "> <%if(list.MarketPrice!=0) {
out.println(list.MarketPrice);
}else{
out.println( " ");
}%> </th>
</tr>
<tr>
<th scope= "row "> 当前价格 </th>
<th scope= "row "> <%= list.Price %> </th>
</tr>
<tr>
<th scope= "row "> 商品介绍 </th>
<th scope= "row "> <%= list.Description %> </th>
</tr>
</table>
<td width=40 height=30> </td>
<tr> <td> </td>
<p>
<%--
<% String UserName=request.getParameter( "UserName ");
if (UserName==null)
%>
<span class= "style1 "> 注意:您是游客身份!登录后才可购物 </span> <span class= "style2 style1 "> 。 </span>
<%
else
%>
<input name= "button " type= "button " onClick= "addtocart(form1); " value= "购买 ">
<input type= "button " value= "关闭 " onClick= "window.close(); ">
--%>
</form>
</div>
</body>
</html>
[解决办法]
rs=databean.executeQuery(sql); 后面需要
rs.next();
才可以取到第一条记录
[解决办法]
你没有把东西取出来呀
[解决办法]
String sql= "SELECT * FROM wares where Id= ' "+Id+ " ' ";
改为:
String sql= "SELECT * FROM wares where Id= "+Id;
试试.....
[解决办法]
String sql= "select * from yonghu1 ";
ResultSet rs=stat.executeQuery(sql);
%>
<table width= "800 ">
<tr>
<td width= "200 "> id </td>
<td width= "200 "> title </td>
<td width= "200 "> use </td>
<td width= "200 "> pwd </td>
</tr>
<% while(rs.next()){
String id=rs.getString( "id ");
String title=rs.getString( "title ");
String use=rs.getString( "use ");
String pwd=rs.getString( "pwd ");%>
<tr>
<td> <%=id%> </td>
<td> <%=title%> </td>
<td> <%=use%> </td>
<td> <%=pwd%> </td>
</tr>
<%} %>
<tr> </tr>
</table>
这是我刚写的数据库查询显示 你看看对你有启发没