当前位置: 代码迷 >> Java Web开发 >> Hibernate+Struts2实现查询操作,不报错,Hibernate显示查询语句也正确,jsp页面就是不显示查询结果!解决方法
  详细解决方案

Hibernate+Struts2实现查询操作,不报错,Hibernate显示查询语句也正确,jsp页面就是不显示查询结果!解决方法

热度:89   发布时间:2016-04-17 11:09:10.0
Hibernate+Struts2实现查询操作,不报错,Hibernate显示查询语句也正确,jsp页面就是不显示查询结果!!!!!
rt。。。。。
代码如下:
BookDao类:
public List<Book> queryAll(){
List<Book> list=null;
String hql="from Book as b order by b.id";
Query query=session.createQuery(hql);
list=query.list();
return list;
}
BookAction类:
//查找全部
public String list(){
list=new BookDao().queryAll();
return SUCCESS;
}
listBooks页面:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>所有图书</title>
</head>

<body>
<h1>所有图书</h1>
<table>
<tr>
<td width="60">ID</td>
<td width="100">书名</td>
<td width="60">价格</td>
<td width="60">&nbsp;</td>
</tr>
<s:iterator value="books">
<tr>
<td>
<a href="<s:url action="editbook%{id}"/>"><s:property value="id" /></a>
</td>
<td>
<s:property value="name" />
</td>
<td>
<s:property value="price" />
</td>
<td>
<a href="<s:url action="deletebook%{id}"/>">删除</a>
</td>
</tr>
</s:iterator>
</table>
<p>
<a href="<s:url action="editbook" includeParams="none"/>">创建新的图书</a>
</body>
</html>
struts2配置文件:
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
 <include file="struts-default.xml"></include>  
<constant name="struts.i18n.encoding" value="gbk"/>
<package name="default" extends="struts-default">
  <!-- 列出所有图书 -->
  <action name="listbook" class="com.pb.action.BookAction" method="list">
  <result>listbooks.jsp</result>
  <interceptor-ref name="basicStack"></interceptor-ref>
  </action>
   
  <!-- 分类的创建和更新 -->
  <action name="editbook*" class="com.pb.action.BookAction">
  <param name="id">{1}</param>
  <result name="success">editBook.jsp</result>
  <interceptor-ref name="static-params"></interceptor-ref>
  <interceptor-ref name="basicStack"></interceptor-ref>
  </action>
 
  <!-- 保存新创建的分类和更新后的分类 -->
  <action name="savebook" class="com.pb.action.BookAction" method="save">
  <result name="input">editBook.jsp</result>
  <result type="redirect">listbook.action</result>
  </action>
   
  <!-- 删除分类 -->
  <action name="deletebook*" class="com.pb.action.BookAction" method="delete">
  相关解决方案