return dao;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
Pagination类:
public class public class Pagination {
private int rowCount;
private int rowOfPage=15;
private int curPage = 1;
private int pageCount;
public Pagination() {
}
public Pagination(int rowCount) {
setRowCount(rowCount);
}
public Pagination(int rowCount, int rowOfPage) {
setRowCount(rowCount);
setRowOfPage(rowOfPage);
}
public void setRowCount(int rowCount){
this.rowCount=rowCount;
init();
}
public int getRowCount() {
return rowCount;
}
public void setCurPage(int pageNum) {
this.curPage = pageNum;
}
public void setRowOfPage(int rowOfPage) {
this.rowOfPage = rowOfPage;
init();
}
private void init(){
pageCount=(int) java.lang.Math.ceil((double)rowCount / (double)rowOfPage);
}
public int getCurPage(){
return curPage;
}
public int getPageCount(){
return pageCount;
}
public int getFirst() {
return 1;
}
public int getNext() {
if (pageCount> curPage) {
return curPage+1;
} else {
return pageCount;
}
}
public int getPrevious() {
if (curPage > 1){
return curPage - 1;
}
return 1;
}
public int getLast() {
return pageCount;
}
public int getStartRow() {
return (this.curPage - 1) * this.rowOfPage;
}
public int getEndRow() {
return curPage * this.rowOfPage;
}
}
{
private int rowCount;
private int rowOfPage=15;
private int curPage = 1;
private int pageCount;
public Pagination() {
}
public Pagination(int rowCount) {
setRowCount(rowCount);
}
public Pagination(int rowCount, int rowOfPage) {
setRowCount(rowCount);
setRowOfPage(rowOfPage);
}
public void setRowCount(int rowCount){
this.rowCount=rowCount;
init();
}
public int getRowCount() {
return rowCount;
}
public void setCurPage(int pageNum) {
this.curPage = pageNum;
}
public void setRowOfPage(int rowOfPage) {
this.rowOfPage = rowOfPage;
init();
}
private void init(){
pageCount=(int) java.lang.Math.ceil((double)rowCount / (double)rowOfPage);
}
public int getCurPage(){
return curPage;
}
public int getPageCount(){
return pageCount;
}
public int getFirst() {
return 1;
}
public int getNext() {
if (pageCount> curPage) {
return curPage+1;
} else {
return pageCount;
}
}
public int getPrevious() {
if (curPage > 1){
return curPage - 1;
}
return 1;
}
public int getLast() {
return pageCount;
}
public int getStartRow() {
return (this.curPage - 1) * this.rowOfPage;
}
public int getEndRow() {
return curPage * this.rowOfPage;
}
}
Controller层代码:
Action类:
public abstract class Action {
protected final String SUCCESS="success";
protected final String FAILURE="failure";
protected ActionMessage message=new ActionMessage();
protected Connection conn;
protected abstract String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException ;
public String process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("message", message);
return execute(request, response);
}
public void setConn(Connection conn){
this.conn=conn;
}
protected abstract DTO initDTO(HttpServletRequest request);
protected abstract boolean validate(DTO dto);
}
ActionConfig类:
public class ActionConfig {
private static ActionConfig actionConfig;
private Map<String,ActionInfo> actionInfos=new HashMap<String, ActionInfo>();
private ActionConfig(URL url) throws JDOMException, IOException{
SAXBuilder builder=new SAXBuilder();
Document doc = builder.build(url);
List<Element> list = XPath.selectNodes(doc,"//action-config/action");
Iterator<Element> iter=list.iterator();
while(iter.hasNext()){
Element actionElt=iter.next();
ActionInfo actionInfo=getActionInfo(actionElt);
actionInfos.put(actionInfo.getPath(), actionInfo);
}
}
private ActionInfo getActionInfo(Element actionElt) {
ActionInfo action=new ActionInfo();
action.setPath(actionElt.getAttributeValue("path"));
action.setActionClass(actionElt.getAttributeValue("actionClass"));
List<Element> list = actionElt.getChildren();
Iterator<Element> iter=list.iterator();
while(iter.hasNext()){
Element forwardElt=iter.next();
ActionForward forward=getForward(forwardElt);
action.addActionForward(forward);
}
return action;
}
private ActionForward getForward(Element forwardElt) {
ActionForward actionForward=new ActionForward();
actionForward.setName(forwardElt.getAttributeValue("name"));
actionForward.setPath(forwardElt.getAttributeValue("path"));
actionForward.setRedirect(Boolean.parseBoolean(forwardElt.getAttributeValue("redirect")));
return actionForward;
}
public static void init(URL url) throws JDOMException, IOException{
if(actionConfig==null){
actionConfig=new ActionConfig(url);
}
}
public static ActionInfo getActionInfo(String path){
if(actionConfig==null){
System.out.println("没有初始化"); |