页面只显示列名,不显示数据库里的数据

从书上copy了个struts2和hibernate的例子,数据库能够连接,但是没法显示,是不是哪块代码写错了

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);
  //if(all.equals(null)){
   System.out.println("all null!!");
  //}
  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>
  </action>
   
  <!--定义add的Action-->
  <action name="add" class="com.javaweb.action.AddAction">
  <!--定义处理结果与视图资源的关系-->
   <result name="SUCCESS" type="redirect">/success.jsp</result>
  
  </action>
  
  <!--定义delete的Action-->
  <action name="delete" class="com.javaweb.action.DeleteAction">
  <!--定义处理结果与视图资源的关系-->
   <result name="SUCCESS" type="redirect">/showAll.action</result> 
  </action>
  
  <!--定义update的Action-->
  <action name="update" class="com.javaweb.action.UpdateAction">
  <!--定义处理结果与视图资源的关系-->
   <result name="SUCCESS" type="redirect">/showAll.action</result> 
  </action>
  
  
  </package>
</struts>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值