日期:2014-05-18  浏览次数:20590 次

页面只显示列名,不显示数据库里的数据
从书上copy了个struts2和hibernate的例子,数据库能够连接,但是只显示各字段名称,没法显示库里的数据,iterator没有使用到。是不是哪块代码写错了。数据库的表设计得很简单,三个字段id name price,求大神帮忙。
 
showAllInfo.jsp代码
 
<%@ page language="java" contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <title>产品列表</title>
 </head>
 <body bgcolor="#CCDDEE">
 <center>
 <h2>产品列表</h2>
 
<table border="2" bgcolor="AACCBBDD">
 <tr>
 <td>产品</td>
 <td>产品名称</td>
 <td>产品价格</td>
 <td>是否删除</td>
 <td>是否更新</td>
 </tr>
 
<s:iterator value="#request.all" id="product">
 <tr>
 <td><s:property value="#product.id"/></td>
 <td><s:property value="#product.name"/></td>
 <td><s:property value="#product.price"/></td>
 <td><a href="delete.action?id=<s:property value='#product.id'/>">删除</a></td>
 <td><a href="update.jsp?id=<s:property value='#product.id'/>">更新</a></td>
 </tr>
 </s:iterator>
 </table>
 
<a href="add.jsp">添加产品</a>
 
</center>
 </body>
 </html>
 
showAllAction.java代码
 
//显示所有信息
 package com.javaweb.action;
 import java.util.List;
 import net.hncu.factory.ServiceFactory;
 import org.apache.struts2.ServletActionContext;
 import com.javaweb.service.*;
 import com.opensymphony.xwork2.ActionSupport;
 
public class ShowAllInfoAction extends ActionSupport{
 
 public String execute()throws Exception{
   
   ProductService ps=ServiceFactory.getServiceInstance();
   List all=ps.queryAllProduct();
   ServletActionContext.getRequest().setAttribute("all", all);
      return SUCCESS;
  }
 }
 

struts.xml配置文件
 
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
 <struts>
  
  <package name="struts2" extends="struts-default" namespace="/" abstract="true">
   
   <!--定义showAll的Action-->
   <action name="showAllInfo" class="com.javaweb.action.ShowAllInfoAction">
   <result name="SUCCESS">/showAll.action</result>
   <result name="input">/add.jsp</result>
   <result name="error">add.jsp</result>
  &