jsp统一实用分页

jsp统一实用分页
pagination.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<SCRIPT type="text/javascript">

function trim(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
}

function selectPage(input){
var value = trim(input.value);
if(value == ""){
return;
}

if(/\d+/.test(value)){
input.form.submit();
return;
}
alert("请输入正确的页数");
input.focus();
}

</SCRIPT>
<div class="pagech">
<!-- action中要加一个url变量 -->
<s:if test="page.totalPages != 0">
<s:url action="%{#request.url}" id="first">
<s:param name="page.pageNo" value="1"></s:param>
</s:url>
<s:url action="%{#request.url}" id="next">
<s:param name="page.pageNo"
value="page.pageNo+1">
</s:param>
</s:url>
<s:url action="%{#request.url}" id="prior">
<s:param name="page.pageNo"
value="page.pageNo-1"></s:param>
</s:url>
<s:url action="%{#request.url}" id="last">
<s:param name="page.pageNo" value="page.totalPages"></s:param>
</s:url>
<s:if test="page.pageNo == 1">
<span class="current">首页</span>
<span class="current">上一页</span>
</s:if>
<s:else>
<s:a href="%{first}">首页</s:a>
<s:a href="%{prior}">上一页</s:a>
</s:else>
<s:if
test="page.pageNo == page.totalPages || page.totalPages == 0">
<span class="current">下一页</span>
<span class="current">末页</span>
</s:if>
<s:else>
<s:a href="%{next}">下一页</s:a>
                  <s:a href="%{last}">末页</s:a>
</s:else>
<span class="jumplabel">跳转到</span>
<s:form action="%{#request.url}" theme="simple"
cssStyle="display:inline">
<s:hidden name="page.totalPages" value="%{page.totalPages}"></s:hidden>
<input type="text" name="page.pageNo" size="2" value="${page.pageNo}"
onblur="selectPage(this)" />
</s:form>

<span class="jumplabel">页</span>
<span class="jumplabel">共<s:property
value="page.totalCount" />条</span>
<span class="jumplabel">当前是第<s:property
value="page.pageNo" />/<s:property
value="page.totalPages" />页</span>


</s:if>

</div>



显示页面引用
<div>
      <jsp:include page="pagination.jsp" />
</div>

action中加一个private String url;
getter/setter方法,
符值
url="abc.action";

要有一个page.java分页类

你可能感兴趣的:(java,jsp,struts)