Posted on 2008-04-01 16:13
G_G 閱讀(2090)
評論(1) 編輯 收藏 所屬分類:
JspTag
上一個blog中 粗略的使用了下
分頁標簽使用 pg使用問題還是有很多 如 分頁中亂碼、多java代碼塊
下面用一個 <jsp:include >來解決這些問題。
??? <!-- 使用寫好的分頁jsp 當中需要參數為 count 總結果個數 / maxPageItems(可選默認10)頁面顯示行數 / goUrl (可選默認本頁) 跳轉路徑 /? params? request中參數 應為亂碼問題 傳給下一個頁面 需要使用URLDecoder.decode(...) 如:String productName = URLDecoder.decode( request.getParameter("productName")==null?"":request.getParameter("productName"),"utf8" );
??? ?
??? -->
??? <jsp:include?page="../jspUtil/page.jsp">
????????<jsp:param?name="count"?value="<%=OrderServiceImp.getOrdersCount(beginTime,endTime,userName,companyName,productName,null,zq)%>"??/>
????????????<jsp:param?name="maxPageItems"?value="10"?/>
????????
????????????<jsp:param?name="goUrl"?value="/zhongqi/seleProduct.do"?/>
????????
????????<jsp:param?name="params"?value="beginTime"?/>
????????<jsp:param?name="params"?value="endTime"?/>
????????<jsp:param?name="params"?value="userName"?/>
????????<jsp:param?name="params"?value="companyName"/>
????????<jsp:param?name="params"?value="productName"?/>
????????
????</jsp:include>
page.jsp
<%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%>
<%@page?import="java.net.URLEncoder"%>
<%@page?import="java.net.URLDecoder"%>
<%@?taglib?prefix="pg"?uri="/WEB-INF/pager-taglib.tld"?%>
<%
????int?count?=?Integer.parseInt(?request.getParameter("count")?);
????int?maxPageItems?=?Integer.parseInt(?request.getParameter("maxPageItems")==null?"10":request.getParameter("maxPageItems")?);
????
????//參數設置?<jsp:param?name="params"?value="xx"??/>
????String[]?params?=?(String[])request.getParameterMap().get("params");
????
????String?goUrl?=?request.getParameter("goUrl");
????
%>
<div?id="bgee">
<div?align="center">
<pg:pager
??id="pager"
??url="<%=goUrl%>"
??items='<%=count%>'
??maxPageItems="<%=maxPageItems?%>"
??export="offset,currentPageNumber=pageNumber"
??isOffset="false"
??scope="request">
??
?? <%?
????for(?String?str?:?params?)?{
????????if?(request.getParameter(str)?!=?null?&&?!request.getParameter(str).equals(""))?{%>
????????????????<pg:param?name="<%=str?%>"?value='<%=?URLEncoder.encode(?URLDecoder.decode(request.getParameter(str),"utf-8"),"utf-8")%>'/>
????????<%?}
??? }%>
<pg:index>
<pg:prev?ifnull="true">
<span>
??????<%?if?(pageUrl?!=?null)?{?%>
????????<A?HREF="<%=?pageUrl?%>"><?上一頁</A>
??????<%?}?%>
</span>
</pg:prev>
??<pg:pages?export="pageUrl,?pageNumber">
<%?if?(pageNumber?==?currentPageNumber)?{?%>
?<span><%=?pageNumber?%></span>
<%}?else?{%>
?<a?href='<%=pageUrl%>'><%=?pageNumber?%></a>
<%}%>
</pg:pages>
<pg:next?ifnull="true">
<%?if?(pageUrl?!=?null)?{?%>
??<a?href='<%=pageUrl%>'>下一頁?></a>
<%}%>
</pg:next>
</pg:index>
</pg:pager>
????</div>
</div>