你有没有把startPage和endPage 以及最后的 PagingBar.toString() 打印出来看看?
总感觉是你中间那段给startPage和endPage赋值有些剞劂呢?
总感觉是你中间那段给startPage和endPage赋值有些剞劂呢?
解决方案 »
- JDBC连接问题
- 在jsp中定义函数出错? 急
- 如何在myeclipse中把HTML标签转换成Struts HTML标签?
- 在框架中如何实现两个页面的信息传递
- 下面这个GB2unicode函数是不是对大小写不敏感
- java连接数据库后得到的值怎么样传递给JAVASCRIPT中的变量。
- Struts2 初学遇到:The requested resource is not available.
- Servlet编译时出现的抛出例外不能覆盖的错误,请解决。
- help!!-----Online----现给分!!!
- 提问一个大家都很迷茫地问题!!!!!!!!挑战高手!!!!!!!!
- 爬取页面的内容问题
- c3p0 不能连接到oracle数据库
protected Locale locale = null; // 本地语言信息
protected MessageResources message = null;// 消息资源 @Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 获取Locale信息
this.locale = this.getLocale(request);
// 获取消息资源对象
this.message = this.getResources(request);
// 如果用户没有登录,跳转到登录页面
//if (request.getSession().getAttribute("user") == null) {
//return mapping.findForward("login");
//}
return super.execute(mapping, form, request, response);
} /**
* 分页
* @param hql hql语句(不包含select,从from子句开始)
* @param recPerPage 每页的记录数
* @param currPage 当前页码
* @param action 请求提交的action地址
* @param where 条件数组
* @return Map集合(装载结果集对象及分页条)
*/
public Map getPage(String hql, int recPerPage, String currPage,
String action, Object[] where) {
// 实例化一个Map对象
Map map = new HashMap();
// 分页条
StringBuffer pagingBar = new StringBuffer();
List list = null; // 结果集
int iCurrPage = 1; // 当前页码
// 如果传递了页码则对当前页码赋值
if (currPage != null && !currPage.isEmpty()) {
iCurrPage = Integer.parseInt(currPage);
}
// 实例化SupperDao对象
SupperDao dao = new SupperDao();
int pages = 0; // 总页数
// 获取总记录数
Long l = (Long) dao.uniqueResult("select count(*) " + hql, where);
int count = l.intValue(); // 将总记录数转为int型
if (count > 0) {
// 计算总页数
if (count % recPerPage == 0) {
pages = count / recPerPage;
} else {
pages = count / recPerPage + 1;
}
if (iCurrPage > pages) {
iCurrPage = pages;
}
if (iCurrPage < 1) {
iCurrPage = 1;
}
// 分页查询获取结果集
list = dao.findPaging(hql, (iCurrPage - 1) * recPerPage,
recPerPage, where);
// 构造分页条
pagingBar.append("<form name='pagingForm' action='" + action
+ "' method='post'>");
// 在分页条中添加总记录数
pagingBar.append(message.getMessage(locale, "page.totalRecord")
+ count);
pagingBar.append(" ");
pagingBar.append(message.getMessage(locale, "system.total") + " "
+ pages + " " + message.getMessage(locale, "page.page"));
pagingBar.append(" ");
// 页数大于1显示上一页超链接,否则不显示超链接
if (iCurrPage > 1) {
pagingBar.append("<a href=" + action + "&currPage=1>"
+ message.getMessage(locale, "page.first") + "</a>");
pagingBar.append(" ");
pagingBar.append("<a href=" + action + "&currPage="
+ (iCurrPage - 1) + ">"
+ message.getMessage(locale, "page.previous") + "</a>");
pagingBar.append(" ");
} else {
pagingBar.append(message.getMessage(locale, "page.first"));
pagingBar.append(" ");
pagingBar.append(message.getMessage(locale, "page.previous"));
pagingBar.append(" ");
}
// 显示当前页码
pagingBar.append("<font color='red'>" + iCurrPage + "</font>");
pagingBar.append(" ");
// 页数小于总页数显示下一页超链接,否则不显示超链接
if (iCurrPage < pages) {
pagingBar.append("<a href=" + action + "&currPage="
+ (iCurrPage + 1) + ">"
+ message.getMessage(locale, "page.next") + "</a>");
pagingBar.append(" ");
pagingBar.append("<a href=" + action + "&currPage=" + pages
+ ">" + message.getMessage(locale, "page.last")
+ "</a>");
} else {
pagingBar.append(message.getMessage(locale, "page.next"));
pagingBar.append(" ");
pagingBar.append(message.getMessage(locale, "page.last"));
}
pagingBar.append(" ");
pagingBar.append("<input type='text' name='currPage' size='1'>");
pagingBar.append("<input type='submit' value='GO'>");
pagingBar.append("</form>");
}
map.put("list", list);// 结果集
map.put("bar", pagingBar.toString());// 分页条的字符串形式
return map;
}
}具体要怎么修改呢?谢谢!!
1、这不是我要的结果,我想从第1页开始显示页码,而且总页数不超过10页都显示,超过就显示省略号像这个网页显示
http://gzs.sgzjkj.com/zylist.aspx?classid=3&itemid=9
2、还有一个问题,页码链接有问题,翻不到指定的页面
pagingBar.append("<a href=" + action + "&currPage=" + pages + ">"+i+"</a> ");
不知怎么修改。
辛苦各位大侠!
1、这不是我要的结果,我想从第1页开始显示页码,而且总页数不超过10页都显示,超过就显示省略号像这个网页显示
http://gzs.sgzjkj.com/zylist.aspx?classid=3&itemid=9
2、还有一个问题,页码链接有问题,翻不到指定的页面
pagingBar.append("<a href=" + action + "&currPage=" + pages + ">"+i+"</a> ");
不知怎么修改。
辛苦各位大侠!