/jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="certificateform" type="com.xindeco.presentation.graduatedata.Certificateform" />
</form-beans>
<global-forwards>
<forward name="error" path="/error/error.jsp" />
</global-forwards>
<action-mappings>
<action name="certificateform" parameter="LIST" path="/graduatedata/list" scope="request" type="com.xindeco.presentation.graduatedata.CertificateAction" validate="true">
<forward name="success" path="/graduatedata/listcertificate.jsp" />
</action>
</action-mappings>
……
</struts-config>
7、最后当然是最重要的分页代码了:Pager.java
java代码:
代码:
package com.xindeco.common;
import java.util.* ;
public class Pager {
private static int MAX_PAGE_INDEX = 10; //页脚显示多少页
private static String HEADER = "Result page";
public static String generate(int offset, int length, int size, String url) {
if (length > size) {
String pref;
if (url.indexOf("?") > -1) {
pref = "&";
} else {
pref = "?";
}
String header = "<font face=''Helvetica'' size=''-1''>"+HEADER+": ";
if (offset > 0) {
header += "&<a href=\""+url+pref+"pager.offset="+(offset-size)+"\">[<< Prev]</a>\n";
}
int start;
int radius = MAX_PAGE_INDEX/2*size;
if (offset < radius) {
start = 0;
} else if(offset < length-radius) {
start = offset - radius;
} else {
start = (length/size-MAX_PAGE_INDEX)*size;
}
for(int i=start;i<length && i < start + MAX_PAGE_INDEX*size;i+=size) {
if (i == offset) {
header += "<b>"+(i/size+1)+"</b>\n";
} else {
header += "&<a href=\""+url+pref+"pager.offset="+i+"\">"+(i/size+1)+"</a>\n";
}
}
if(offset < length - size) {
header += "&<a href=\""+url+pref+"pager.offset="+((int)offset+(int)size)+"\">[Next >>]</a>\n";
}
header += "</font>";
return header;
} else {
return "";
}
}
}
这部分代码的实现相当简洁,但已经足够完成所需了。 |