关于使用logic:iterate 整合struts 和hiberante分页的问题

海蓝树 2008-06-30 09:51:58
我有的项目,在使用logic:iterate分页的屏幕就一片空白。


package com.mine.struts.action;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.mine.server.Service;



public class User_showAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {



// 分析当前页码
String pageString=request.getParameter("page");
if(pageString == null || pageString.length() == 0) {
pageString = "1";
}
int currentPage= 0 ;
try {
currentPage = Integer.parseInt(pageString);// 当前页码
} catch(Exception e) {}
if(currentPage == 0) {
currentPage = 1;
}

int pageSize = 3;//每页显示的数据数
// 读取数据
Service manager = new Service();
List users = manager.findPagedAll(currentPage, pageSize);
request.setAttribute("users",users);// 保存用户列表
request.setAttribute("totalPage",manager.getTotalPage(pageSize));// 保存总页数
request.setAttribute("totalCount", manager.getTotalCount());//
//保存记录总数
request.setAttribute("currentPage", currentPage);// 保存当前页码
return mapping.findForward("display");
}
}



JSP页面:
<%@ page language="java" import="com.mine.server.*,java.util.*"
pageEncoding="GBK"%>
<%@ page contentType="text/html;charset=GBK"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

<%
String path = request.getContextPath();
String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>用户列表页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<style>

a:hover {color:red;text-decoration:none}
</style>
</head>
<body><b>用户列表页面</b><br>

<table width="100%" border="0">

</table>

<table width="80%" border="1" cellpadding="0"
style="border-collapse: collapse; " bordercolor="#000000">
<tr>
<td>用户名</td>
<td>密码</td>
<td>地址</td>
<td>电话</td>
<td>邮箱</td>
<td>性别</td>
<td>爱好</td>
<td>操作</td>
</tr>

<logic:iterate name="users" id="user">
<tr>
<td>${user.username}</td>
<td>${user.password}</td>
<td>${user.address}</td>
<td>${user.tel}</td>
<td>${user.email}</td>
<td>${user.sex}</td>
<td>${user.enjoy}</td>
<td>${user.content}</td>
<td><a href="edit.html?id=${user.id}">修改</a></td>
</tr>
</logic:iterate>

</table> 共${totalCount}个用户
第${currentPage}页/共${totalPage}页

<c:if test="${currentPage > 1}">
[ <a
href="${pageContext.request.contextPath}/user_show.html?page=${currentPage-1
}">上一页</a> ]
</c:if>

<c:if test="${currentPage <= 1}">
[ 上一页 ]
</c:if>
<c:if test="${currentPage < totalPage}">
[ <a
href="${pageContext.request.contextPath}/user_show.html?page=${currentPage+1
}">下一页</a> ]
</c:if>
<c:if test="${currentPage >= totalPage}">
[ 下一页 ]
</c:if>
<%-- 输出 JavaScript 跳转代码 --%>
<script>
// 页面跳转函数
// 参数: 包含页码的表单元素,例如输入框,下拉框等
function jumpPage(input) {
// 页码相同就不做跳转
if(input.value == ${currentPage}) {
return;
}
var newUrl = "${pageContext.request.contextPath}/user_show.html?page=" +
input.value;
document.location = newUrl;
}
</script>
转到
<!-- 输出 HTML SELECT 元素, 并选中当前页面编码 -->
<select onchange='jumpPage(this);'>
<c:forEach var="i" begin="1" end="${totalPage}">
<option value="${i}"
<c:if test="${currentPage == i}">
selected
</c:if>
>第${i}页</option>
</c:forEach>
</select>
输入页码:<input type="text" value="${currentPage}" id="jumpPageBox"
size="3">
<input type="button" value="跳转"
onclick="jumpPage(document.getElementById('jumpPageBox'))">

</body>
</html>
...全文
88 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
海蓝树 2008-06-30
  • 打赏
  • 举报
回复
使用 <bean:write>输出了这个:[com.mine.hib.T3@6c5356, com.mine.hib.T3@97d3f0, com.mine.hib.T3@1db6942]
海蓝树 2008-06-30
  • 打赏
  • 举报
回复
没有任何错误提示,就是空白一片,users中有值,而且hql也可以执行,我感觉就是到了最后输出或者list中值出了问题,请各位多多帮忙了
craky 2008-06-30
  • 打赏
  • 举报
回复
发错地方了~~~~~~~~~~~~~~~~~~~~
xql80329 2008-06-30
  • 打赏
  • 举报
回复
除了页面空白 还有什么错误信息提示吗?

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧