(原创)一个Struts实现分页,增删改查,Tiles,国际化的DEMO

类别:Java 点击:0 评论:0 推荐:

这个DEMO供大家一起探讨学习Struts,因为工作太累,没精力给大家解释实现原理。如果看不懂,没关系。只是说明JSP基础还没有到火候,不要心急,回去强化下JSP+Servlet,基础扎实了,自然能够看懂我写的代码。这个DEMO借鉴了网上很多前人的经验,在此一并谢谢。
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>BookShopMod</display-name>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>application</param-name>
      <param-value>ApplicationResources</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
  </welcome-file-list>
  <taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/camel-define.tld</taglib-uri>
    <taglib-location>/WEB-INF/camel-define.tld</taglib-location>
  </taglib>
</web-app>
Struts-config.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
  <form-beans>
    <form-bean name="bookForm" type="com.bookshop.form.BookForm"/>
    <form-bean name="operatorForm" type="com.bookshop.form.OperatorForm"/>
    <form-bean name="findRecordForm" type="com.bookshop.form.FindRecordForm"/>
  </form-beans>
  <global-forwards>
    <forward name="index" path="/index.jsp"/>
    <forward name="browser" path="/show.jsp"/>
    <forward name="global_error" path="/error.jsp"/>
  </global-forwards>
  <action-mappings>
    <action input="/show.jsp" name="bookForm" parameter="operator" path="/operatorAction" scope="session" type="com.bookshop.action.OperatorAction" validate="false">
      <forward name="operatorok" path="/success.jsp" redirect="true"/>
      <forward name="showFirstPage" path="/operatorAction.do?operator=showFirstPage"/>
      <forward name="showPreviousPage" path="/operatorAction.do?operator=showPreviousPage"/>
      <forward name="showNextPage" path="/operatorAction.do?operator=showNextPage"/>
      <forward name="showLastPage" path="/operatorAction.do?operator=showLastPage"/>
      <forward name="showAddRecord" path="/editrecord.jsp?operator=addRecord" redirect="true"/>
      <forward name="showModifyRecord" path="/editrecord.jsp?operator=modifyRecord"/>
      <forward name="showFindRecord" path="/findrecord.jsp" redirect="true"/>
    </action>
    <action input="/findrecord.jsp" name="findRecordForm" path="/findRecordAction" scope="session" type="com.bookshop.action.FindRecordAction" validate="false"/>
  </action-mappings>
  <plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
  </plug-in>
</struts-config>
tiles-defs文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<tiles-definitions>
  <definition name="base-definition" path="layout.jsp">
    <put name="head" value="head.jsp" />
    <put name="left" value="left.jsp" />
    <put name="body" />
    <put name="foot" value="foot.jsp" />
  </definition>
  <definition extends="base-definition" name="index-definition">
    <put name="body" value="index_body.jsp" />
  </definition>
  <definition extends="base-definition" name="show-definition">
    <put name="body" value="show_body.jsp" />
  </definition>
  <definition extends="base-definition" name="edit-definition">
    <put name="body" value="edit_body.jsp" />
  </definition>
  <definition extends="base-definition" name="find-definition">
    <put name="body" value="find_body.jsp"/>
    </definition>
   <definition extends="base-definition" name="success-definition">
    <put name="body" value="success_body.jsp" />
  </definition>
  <definition extends="base-definition" name="error-definition">
    <put name="body" value="error_body.jsp"/>
    </definition>
</tiles-definitions>
camel-define文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>camel</shortname>
<uri>http://jakarta.apache.org/struts/tags-bean</uri>
<tag>
<name>isLastPage</name>
<tagclass>com.bookshop.util.IsLastTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>page</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
上面几个文件和struts-bean.tld,struts-html.tld,struts-tiles.tld,struts-logic.tld都一起位于WEB-INF的根目录下面。
以下是三个Action文件:
/*FindRecordAction.java*/
package com.bookshop.action;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.bookshop.form.FindRecordForm;
import org.apache.struts.action.Action;
import java.util.List;
import java.util.ArrayList;
import com.bookshop.model.Operator;
import com.bookshop.util.PageInfo;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;

public class FindRecordAction
    extends Action {
  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest servletRequest,
                               HttpServletResponse servletResponse) {
    FindRecordForm findRecordForm = (FindRecordForm) actionForm;
    String key = findRecordForm.getFindByKey().trim();
    String value = findRecordForm.getFindByValue().trim();
    List list = new ArrayList();
    list = Operator.getRecords(key, value, 0);
    servletRequest.getSession().setAttribute("books", list);
    if (!list.isEmpty()) {
      servletRequest.getSession().setAttribute("pageinfo",
                                               new PageInfo(Operator.
          getRecordsNumber(), 1));
    }
    else {
      ActionErrors messages = new ActionErrors();
      messages.add(ActionErrors.GLOBAL_MESSAGE,
                   new ActionError("findrecord.jsp.notfound"));
      servletRequest.getSession().setAttribute("pageinfo",
                                               new PageInfo(0, 1));
    }
    return actionMapping.findForward("browser");
  }
}
/*GenericAction.java*/
package com.bookshop.action;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;

public class GenericAction
    extends DispatchAction {
  /*
     public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest servletRequest,
                               HttpServletResponse servletResponse) {
    throw new java.lang.UnsupportedOperationException(
        "Method $execute() not yet implemented.");
     }
   */
  public void saveGlobalErrors(HttpServletRequest httpServletRequest,
                               String errorKey) {
    ActionErrors errors = new ActionErrors();
    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(errorKey));
    if (errors != null) {
      saveErrors(httpServletRequest, errors);
    }
  }

  public ActionForward getIndexForward(ActionMapping actionMapping) {
    return actionMapping.findForward("index");
  }

  public ActionForward getBrowserForward(ActionMapping actionMapping) {
    return actionMapping.findForward("browser");
  }

  public ActionForward showDeleteForward(ActionMapping actionMapping) {
    return actionMapping.findForward("showDelete");
  }

  public ActionForward getOperatorOkForward(ActionMapping actionMapping) {
    return actionMapping.findForward("operatorok");
  }

  public ActionForward getErrorForward(ActionMapping actionMapping) {
    return actionMapping.findForward("global_error");
  }

  public ActionForward getShowAddForward(ActionMapping actionMapping) {
    return actionMapping.findForward("showAddRecord");
  }

  public ActionForward getShowModifyForward(ActionMapping actionMapping) {
    return actionMapping.findForward("showModifyRecord");
  }

  public ActionForward getShowDeleteForward(ActionMapping actionMapping) {
    return actionMapping.findForward("showDeleteRecord");
  }

  public ActionForward getShowFindForward(ActionMapping actionMapping) {
      return actionMapping.findForward("showFindRecord");
  }
}
/*OperatorAction.java*/
package com.bookshop.action;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.bookshop.form.OperatorForm;
import org.apache.struts.action.Action;
import java.util.List;
import org.apache.struts.Globals;
import com.bookshop.util.DBUtil;
import com.bookshop.util.ApplicationUtil;
import com.bookshop.model.Operator;
import java.util.ArrayList;
import com.bookshop.util.PageInfo;
import org.apache.struts.actions.DispatchAction;
import java.util.Map;
import java.util.HashMap;
import com.bookshop.form.BookForm;
import java.util.Locale;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import com.bookshop.util.BookBean;

public class OperatorAction
    extends GenericAction {
    /*
       public ActionForward execute(ActionMapping actionMapping,
                                 ActionForm actionForm,
                                 HttpServletRequest servletRequest,
                                 HttpServletResponse servletResponse) {
      throw new java.lang.UnsupportedOperationException(
          "Method $execute() not yet implemented.");
       }
     */

  //转换为中文页面
  public ActionForward ChangeCH(ActionMapping actionMapping,
                                ActionForm actionForm,
                                HttpServletRequest servletRequest,
                                HttpServletResponse servletResponse) {
    servletRequest.getSession().setAttribute(Globals.LOCALE_KEY, Locale.CHINA);
    return this.getIndexForward(actionMapping);
  }

  //转换为英文页面
  public ActionForward ChangeEN(ActionMapping actionMapping,
                                ActionForm actionForm,
                                HttpServletRequest servletRequest,
                                HttpServletResponse servletResponse) {
    servletRequest.getSession().setAttribute(Globals.LOCALE_KEY, Locale.ENGLISH);
    return this.getIndexForward(actionMapping);
  }

  //链接到首页记录
  public ActionForward showFirstPage(ActionMapping actionMapping,
                                     ActionForm actionForm,
                                     HttpServletRequest httpServletRequest,
                                     HttpServletResponse httpServletResponse) {
    List list = new ArrayList();
    list = Operator.getRecords(0);
    httpServletRequest.getSession().setAttribute("books", list);
    httpServletRequest.getSession().setAttribute("pageinfo",
                                                 new PageInfo(Operator.
        getRecordsNumber(), 1));
    return this.getBrowserForward(actionMapping);
  }

  //链接到上一页记录
  public ActionForward showPreviousPage(ActionMapping actionMapping,
                                        ActionForm actionForm,
                                        HttpServletRequest httpServletRequest,
                                        HttpServletResponse httpServletResponse) {
    List list = new ArrayList();
    PageInfo pageInfo = (PageInfo) httpServletRequest.getSession().getAttribute(
        "pageinfo");
    list = Operator.getRecords( (pageInfo.getPreviousPageNumber() - 1) *
                               ApplicationUtil.recordPerPage);
    httpServletRequest.getSession().setAttribute("books", list);
    httpServletRequest.getSession().setAttribute("pageinfo",
                                                 new PageInfo(Operator.
        getRecordsNumber(), pageInfo.getPreviousPageNumber()));
    return this.getBrowserForward(actionMapping);
  }

  //链接到下一页记录
  public ActionForward showNextPage(ActionMapping actionMapping,
                                    ActionForm actionForm,
                                    HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse) {
    List list = new ArrayList();
    PageInfo pageInfo = (PageInfo) httpServletRequest.getSession().getAttribute(
        "pageinfo");
    list = Operator.getRecords(pageInfo.getCurrentlyPage() *
                               ApplicationUtil.recordPerPage);
    httpServletRequest.getSession().setAttribute("books", list);
    httpServletRequest.getSession().setAttribute("pageinfo",
                                                 new PageInfo(Operator.
        getRecordsNumber(), pageInfo.getNextPageNumber()));
    return this.getBrowserForward(actionMapping);
  }

  //链接到末页记录
  public ActionForward showLastPage(ActionMapping actionMapping,
                                    ActionForm actionForm,
                                    HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse) {
    List list = new ArrayList();
    PageInfo pageInfo = (PageInfo) httpServletRequest.getSession().getAttribute(
        "pageinfo");
    list = Operator.getRecords( (pageInfo.getPageCountNumber() - 1) *
                               ApplicationUtil.recordPerPage);
    httpServletRequest.getSession().setAttribute("books", list);
    httpServletRequest.getSession().setAttribute("pageinfo",
                                                 new PageInfo(Operator.
        getRecordsNumber(), pageInfo.getLastPageNumber()));
    return this.getBrowserForward(actionMapping);
  }

  //取消操作的转向
  public ActionForward cancel(ActionMapping actionMapping,
                              ActionForm actionForm,
                              HttpServletRequest httpServletRequest,
                              HttpServletResponse httpServletResponse) {
    if (isCancelled(httpServletRequest)) {
      return this.getOperatorOkForward(actionMapping);
    }
    return null;
  }

  //查看所有记录
  public ActionForward browser(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse) {
    return this.showFirstPage(actionMapping, actionForm, httpServletRequest,
                              httpServletResponse);
  }

//执行添加记录
  public ActionForward addRecord(ActionMapping actionMapping,
                                 ActionForm actionForm,
                                 HttpServletRequest httpServletRequest,
                                 HttpServletResponse httpServletResponse) {
    BookForm bookForm = (BookForm) actionForm;
    if (Operator.addRecord(bookForm.loadBook()) >= 1) {
      return this.getOperatorOkForward(actionMapping);
    }
    else {
      this.saveGlobalErrors(httpServletRequest, "editrecord.jsp.adderror");
      return this.getErrorForward(actionMapping);
    }
  }

//提交更新操作
  public ActionForward SubmitRecord(ActionMapping actionMapping,
                                    ActionForm actionForm,
                                    HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse) {
    String str = (String) httpServletRequest.getSession().getAttribute("method");
    if (str.equals("addRecord")) {
      return addRecord(actionMapping, actionForm, httpServletRequest,
                       httpServletResponse);
    }
    if (str.equals("modifyRecord")) {
      return modifyRecord(actionMapping, actionForm, httpServletRequest,
                          httpServletResponse);
    }
    else {
      this.saveGlobalErrors(httpServletRequest, "edit.body.error");
      return this.getErrorForward(actionMapping);
    }
  }

//执行修改操作
  public ActionForward modifyRecord(ActionMapping actionMapping,
                                    ActionForm actionForm,
                                    HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse) {
    BookForm bookForm = (BookForm) actionForm;
    if (Operator.modifyRecord(bookForm.loadBook()) != -1) {
      return this.getOperatorOkForward(actionMapping);
    }
    else {
      this.saveGlobalErrors(httpServletRequest, "editrecord.jsp.modifyerror");
      return this.getErrorForward(actionMapping);
    }
  }

//跳转到添加记录编辑页面
  public ActionForward showAdd(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse) {
    httpServletRequest.getSession().setAttribute("bookBean", new BookForm());
    httpServletRequest.getSession().setAttribute("method",
                                                 new String("addRecord"));
    return this.getShowAddForward(actionMapping);
  }

//跳转到修改记录编辑页面
  public ActionForward showModify(ActionMapping actionMapping,
                                  ActionForm actionForm,
                                  HttpServletRequest httpServletRequest,
                                  HttpServletResponse httpServletResponse) {
    BookBean book = new BookBean();
    String str = httpServletRequest.getParameter("bookid").toString();
    book = Operator.getRecord(str);
    httpServletRequest.getSession().setAttribute("bookBean",
                                                 new BookForm(book.getBookId(),
        book.getBookName(), book.getAuthor(), book.getPublish(), book.getPrice()));
    httpServletRequest.getSession().setAttribute("method",
                                                 new String("modifyRecord"));

    return this.getShowModifyForward(actionMapping);
  }

//删除记录
  public ActionForward showDelete(ActionMapping actionMapping,
                                  ActionForm actionForm,
                                  HttpServletRequest httpServletRequest,
                                  HttpServletResponse httpServletResponse) {
    String str = httpServletRequest.getParameter("bookid").toString();
    if (Operator.deleteRecord(str) != -1) {
      return this.getOperatorOkForward(actionMapping);
    }
    else {
      this.saveGlobalErrors(httpServletRequest, "edit.body.error");
      return this.getErrorForward(actionMapping);
    }
  }

  public ActionForward showFind(ActionMapping actionMapping,
                                ActionForm actionForm,
                                HttpServletRequest httpServletRequest,
                                HttpServletResponse httpServletResponse) {
    //传递参数
    httpServletRequest.getSession().setAttribute("bookBean", new BookForm());
    httpServletRequest.getSession().setAttribute("method",
                                                 new String("findRecord"));
    return this.getShowFindForward(actionMapping);
  }
}
以下是三个ActionForm文件:
package com.bookshop.form;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.HashMap;

public class BookForm
    extends ActionForm {
  private String author;
  private String bookId;
  private String bookName;
  private String price;
  private String publish;
  private String beanId;

  public BookForm() {
    this.bookId = "";
    this.bookName = "";
    this.author = "";
    this.publish = "";
    this.price = "";
    this.beanId = "";
  }

  public BookForm(String id, String name, String author, String publish,
                  String price) {
    this.bookId = id;
    this.bookName = name;
    this.author = author;
    this.publish = publish;
    this.price = price;
    this.beanId = id;
  }

  public String getAuthor() {
    return author;
  }

  public void setAuthor(String author) {
    this.author = author;
  }

  public void setPublish(String publish) {
    this.publish = publish;
  }

  public void setPrice(String price) {
    this.price = price;
  }

  public void setBookName(String bookName) {
    this.bookName = bookName;
  }

  public void setBookId(String bookId) {
    this.bookId = bookId;
  }

  public String getBookId() {
    return bookId;
  }

  public String getBookName() {
    return bookName;
  }

  public String getPrice() {
    return price;
  }

  public String getPublish() {
    return publish;
  }

  public String getBeanId() {
    return this.beanId;
  }

  public void setBeanId(String beanId) {
    this.beanId = beanId;
  }

  public Map loadBook() {
    Map record = new HashMap();
    record.put("column1", this.getBookId().trim());
    record.put("column2", this.getBookName().trim());
    record.put("column3", this.getAuthor().trim());
    record.put("column4", this.getPublish().trim());
    record.put("column5", this.getPrice().trim());
    return record;
  }

  public ActionErrors validate(ActionMapping actionMapping,
                               HttpServletRequest httpServletRequest) {
    ActionErrors errors = new ActionErrors();
    if (this.bookId == null || this.bookId.equals("") ||
        this.bookId.length() < 1) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("book.bookid.error"));
    }
    if (this.bookName == null || this.bookName.equals("") ||
        this.bookName.length() < 1) {
      errors.add(ActionErrors.GLOBAL_ERROR,
                 new ActionError("book.bookname.error"));
    }
    if (this.author == null || this.author.equals("") ||
        this.author.length() < 1) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("book.author.error"));
    }
    if (this.publish == null || this.publish.equals("") ||
        this.publish.length() < 1) {
      errors.add(ActionErrors.GLOBAL_ERROR,
                 new ActionError("book.publish.error"));
    }
    // if ( (Float.isNaN(this.price)) && (this.price < 0)) {
    if ( (Float.isNaN(Float.parseFloat(this.price))) &&
        (Float.parseFloat(this.price) < 0)) {
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("book.price.error"));
    }
    return errors;
  }
}
/**/
package com.bookshop.form;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;

public class FindRecordForm
    extends ActionForm {
  private String findByKey;
  private String findByValue;
  public String getFindByKey() {
    return findByKey;
  }

  public void setFindByKey(String findByKey) {
    this.findByKey = findByKey;
  }

  public void setFindByValue(String findByValue) {
    this.findByValue = findByValue;
  }

  public String getFindByValue() {
    return findByValue;
  }

  public ActionErrors validate(ActionMapping actionMapping,
                               HttpServletRequest httpServletRequest) {
    /** @todo: finish this method, this is just the skeleton.*/
    ActionErrors errors = null;
    if (this.findByKey.equals("") || this.findByValue.equals("")) {
      errors = new ActionErrors();
      errors.add(ActionErrors.GLOBAL_ERROR,
                 new ActionError("find.jsp.error"));
    }
    return errors;
  }

  public void reset(ActionMapping actionMapping,
                    HttpServletRequest servletRequest) {
  }
}
/**/
package com.bookshop.form;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;

public class OperatorForm
    extends ActionForm {
  private String operator;
  public String getOperator() {
    return operator;
  }

  public void setOperator(String operator) {
    this.operator = operator;
  }

  public ActionErrors validate(ActionMapping actionMapping,
                               HttpServletRequest httpServletRequest) {
    ActionErrors errors = new ActionErrors();
    if (httpServletRequest.getParameter("operator") != null) {
      String lang = httpServletRequest.getParameter("operator");
      /* if ( (lang.length() < 6) || (lang.length() > 6)) {
         errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("index.jsp.operator.error"));
       }
       */
    }
    else {
      errors.add(ActionErrors.GLOBAL_ERROR,
                 new ActionError("index.jsp.operator.null"));
    }
    return errors;

  }

  public void reset(ActionMapping actionMapping,
                    HttpServletRequest servletRequest) {
  }
}
以下是业务类和数据库访问类:
package com.bookshop.model;

import java.util.Map;
import java.util.List;
import com.bookshop.util.*;

public class Operator {

  private static int recordPerPage = ApplicationUtil.recordPerPage;
  //动态SQL
  private static String sqlNumber = "";

  //留出接口设置每页显示多少条记录
  public static void setRecordPerPage(int number) {
    recordPerPage = number;
  }

  public Operator() {
  }

  //获得所有记录集(只查询一页记录)
  public static List getRecords(int startIndex) {
    String sql = "select * from booktab limit ?,?";
    sqlNumber = "select count(*) from booktab";
    return DBUtil.executeQuery(sql, startIndex, recordPerPage);
  }

  //按条件查找记录集(只查询一页记录)
  public static List getRecords(String key, String value, int startIndex) {

    String sql = "select * from booktab where " + key + "='" + value +
        "' limit ?,?";
    sqlNumber = "select count(*) from booktab where " + key + "='" + value +
        "'";
    return DBUtil.executeQuery(sql, startIndex, recordPerPage);
  }

  //查询单条记录 用于修改
  public static BookBean getRecord(String value) {
    String sql = "select * from booktab where bookid='" + value + "'";
    BookBean book = new BookBean();
    book = DBUtil.execQuery(sql);
    return book;
  }

  //添加一条新记录
  public static int addRecord(Map newRecord) {
    String sql =
        "insert into booktab(bookname,author,publish,price,bookid)values(?,?,?,?,?)";
    return DBUtil.execUpdate(sql, newRecord);
  }

  //修改指定的记录
  public static int modifyRecord(Map newRecord) {
    String sql =
        "update booktab set bookname=?,author=?,publish=?,price=? where bookid=?";
    return DBUtil.execUpdate(sql, newRecord);
  }

  //删除指定的记录
  public static int deleteRecord(String value) {
    String sql =
        "delete from booktab where bookid='" + value + "'";
    return DBUtil.execUpdate(sql);
  }

  //获得表中所有记录的条数
  public static int getRecordsNumber() {
    return DBUtil.executeQuery(sqlNumber);
  }

  /*
    public static void main(String[] args) {
      Operator operator = new Operator();
    }
   */
}
/**/
package com.bookshop.util;

import javax.servlet.http.HttpServletRequest;

public class ApplicationUtil {
  public ApplicationUtil() {
  }

  public static final String driver = "org.gjt.mm.mysql.Driver";
  public static final String url ="jdbc:mysql://localhost/bookshop";
  public static final String user = "root";
  public static final String password = "";
  public static final int recordPerPage = 5;

  public static String toGBK(String s) {
    try {
      return new String(s.getBytes("ISO-8859-1"), "gb2312");
    }
    catch (Exception ex) {
      return "";
    }
  }

  public static String getSelfURL(HttpServletRequest req) {
    String s1 = req.getRequestURI();
    String s2 = req.getQueryString();
    if (s2 != null) {
      s1 = s1 + "?" + s2;
    }
    return s1;
  }

  public static void setParam(String param, String value, java.util.HashMap map) {
    String[] p = param.split(";");
    String[] v = value.split(";");
    for (int i = 0; i < p.length; i++) {
      map.put(p[i], v[i]);
    }
  }

}
/**/
package com.bookshop.util;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

public class IsLastTag
    extends TagSupport {
  private String page = "";

  public IsLastTag() {
  }

  public void setPage(String page) {
    this.page = page;
  }

  public String getPage() {
    return this.page;
  }

  public int doStartTag() throws JspException {
    if (this.page != null) {
      //从session里面取出来的是PageInfo对象的引用
      PageInfo pageBean = new PageInfo();
      pageBean = (PageInfo) (pageContext.getSession().getAttribute(this.
          page));
      //只要该PageInfo对象的总页数等于当前页数就不处理主体部分
      if (pageBean.getPageCountNumber() <= pageBean.getCurrentlyPage()) {
        return this.SKIP_BODY;
      }
      else {
        return this.EVAL_PAGE;//否则继续处理主体部分
      }
    }
    else {
      return this.SKIP_BODY;
    }
  }
}
/**/
package com.bookshop.util;

import java.util.List;
import java.util.ArrayList;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class DBUtil {

  public DBUtil() {
  }

  private static String driver = ApplicationUtil.driver;
  private static String url = ApplicationUtil.url;
  private static String user = ApplicationUtil.user;
  private static String password = ApplicationUtil.password;
  private static List list = null;
  private static Connection con = null;
  private static Statement sta = null;
  private static PreparedStatement psta = null;
  private static ResultSet res = null;

//获得满足查询条件的记录行数
  public static int executeQuery(String sql) {
    int countNum = 0;
    try {
      execute(sql);
      while (res.next()) {
        countNum = res.getInt(1);
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      close();
      return countNum;
    }
  }

//删除记录
  public static int execUpdate(String sql) {
    int i = -1;
    try {
      getStatement();
      i = sta.executeUpdate(sql);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      close();
      return i;
    }
  }

//添加新记录
  public static int execUpdate(String sql, Map newRecord) {
    int i = -1;
    try {
      getPreparedStatement(sql);
      if (newRecord != null && !newRecord.isEmpty()) {
        psta.setString(1, (String) newRecord.get("column2"));
        psta.setString(2, (String) newRecord.get("column3"));
        psta.setString(3, (String) newRecord.get("column4"));
        psta.setString(4, (String) newRecord.get("column5"));
        psta.setString(5, (String) newRecord.get("column1"));
      }
      i = psta.executeUpdate();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      close();
      return i;
    }
  }
//查询单个记录(用于修改)
  public static BookBean execQuery(String sql) {
    BookBean book = null;
    try {
      execute(sql);
      while (res.next()) {
        book = new BookBean(ApplicationUtil.toGBK(res.getString(1)),
                            ApplicationUtil.toGBK(res.getString(2)),
                            ApplicationUtil.toGBK(res.getString(3)),
                            ApplicationUtil.toGBK(res.getString(4)),
                            ApplicationUtil.toGBK(res.getString(5))
            );
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      close();
      return book;
    }
  }
//查询记录(只查询指定页要显示的记录)
  public static List executeQuery(String sql, int startIndex, int count) {
    try {
      list = new ArrayList();
      getResultSet(sql, startIndex, count);
      while (res.next()) {
        list.add(new BookBean(ApplicationUtil.toGBK(res.getString(1)),
                              ApplicationUtil.toGBK(res.getString(2)),
                              ApplicationUtil.toGBK(res.getString(3)),
                              ApplicationUtil.toGBK(res.getString(4)),
                              ApplicationUtil.toGBK(res.getString(5))
                 ));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      close();
      return list;
    }
  }

  private static void getConnection() throws Exception {
    Class.forName(driver);
    con = DriverManager.getConnection(url, user, password);
    //con.setAutoCommit(false);
  }

  private static void getPreparedStatement(String sql) throws Exception {
    getConnection();
    psta = con.prepareStatement(sql);
  }

  private static void execute(String sql) throws Exception {
    getStatement();
    res = sta.executeQuery(sql);
  }

  private static void getStatement() throws Exception {
    getConnection();
    sta = con.createStatement();
  }

  private static void getResultSet(String sql, int startIndex, int count) throws
      Exception {
    getPreparedStatement(sql);
    psta.setInt(1, startIndex);
    psta.setInt(2, count);
    res = psta.executeQuery();
  }

//释放资源
  private static void close() {
    try {
      /*
             if(con!=null){
         con.commit();
       }
       */
      if (res != null) {
        res.close();
      }
      if (psta != null) {
        psta.close();
      }
      if (sta != null) {
        sta.close();
      }
      if (con != null) {
        con.close();
      }
    }
    catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
/**/
package com.bookshop.util;

import java.io.Serializable;

public class BookBean
    implements Serializable {
  private String author = "";
  private String bookId = "";
  private String bookName = "";
  private String price = "";
  private String publish = "";

  public BookBean() {
    this.bookId = "";
    this.bookName = "";
    this.author = "";
    this.publish = "";
    this.price = "";
  }

  public BookBean(String bookId, String bookName, String author, String publish,
                  String price) {
    this.author = author;
    this.bookId = bookId;
    this.bookName = bookName;
    this.publish = publish;
    this.price = price;
  }

  public String getAuthor() {
    return author;
  }

  public void setAuthor(String author) {
    this.author = author;
  }

  public void setPublish(String publish) {
    this.publish = publish;
  }

  public void setPrice(String price) {
    this.price = price;
  }

  public void setBookName(String bookName) {
    this.bookName = bookName;
  }

  public void setBookId(String bookId) {
    this.bookId = bookId;
  }

  public String getBookId() {
    return bookId;
  }

  public String getBookName() {
    return bookName;
  }

  public String getPrice() {
    return price;
  }

  public String getPublish() {
    return publish;
  }
  /*
    public static void main(String[] args) {
      BookBean bookbean = new BookBean();
    }
   */
}
/**/
package com.bookshop.util;

import java.io.Serializable;

public class PageInfo
    implements Serializable {

  private int recordCountNumber = 0; //总记录数
  private int pageCountNumber = 0; //总页数
  private int recordPerPage = ApplicationUtil.recordPerPage; //每页记录数
  private int currentlyPage = 0; //当前页数
  private int previousPageNumber = 0; //当前页的前一页数
  private int nextPageNumber = 0; //当前页的后一页数

  public PageInfo() {
  }

//总记录数 当前页码
  public PageInfo(int recordCountNumber,
                  int currentPage) {
    this.recordCountNumber = recordCountNumber;
    if (this.recordCountNumber % this.recordPerPage == 0) {
      this.pageCountNumber = this.recordCountNumber / this.recordPerPage;
    }
    else {
      this.pageCountNumber = (this.recordCountNumber / this.recordPerPage) + 1;
    }
    this.currentlyPage = currentPage;
  }

  public int getRecordCountNumber() {
    return this.recordCountNumber;
  }

  public int getPageCountNumber() {
    return this.pageCountNumber;
  }

  public int getRecordPerPage() {
    return this.recordPerPage;
  }

  public int getCurrentlyPage() {
    return this.currentlyPage;
  }

  public int getLastPageNumber() {
    return this.pageCountNumber;
  }

  public int getPreviousPageNumber() {
    this.previousPageNumber=this.currentlyPage-1;
    return this.previousPageNumber;
  }

  public int getNextPageNumber() {
    this.nextPageNumber = this.currentlyPage + 1;
    return this.nextPageNumber;
  }
}
以下是所有的JSP页面因为使用了Tiles框架,所以好象页面显得很多:
head.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<font color=red><html:errors/></font><br/>
<html:link href="operatorAction.do?operator=ChangeCH">
  <bean:message key="head.language.chinese"/>
</html:link>
<html:link href="operatorAction.do?operator=ChangeEN">
  <bean:message key="head.language.english"/>
</html:link>

left.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:link href="index.jsp">
  <bean:message key="left.link.index"/>
</html:link>
<br/>
<html:link href="operatorAction.do?operator=browser">
  <bean:message key="left.link.show"/>
</html:link>
<br/>
<html:link href="operatorAction.do?operator=showFind">
  <bean:message key="left.link.findbykey"/>
</html:link>
<br/>
<html:link href="operatorAction.do?operator=showAdd">
  <bean:message key="left.link.addnew"/>
</html:link>
<br/>

foot.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<center>
  <bean:message key="foot.copyright"/>
</center>

layout.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<html:html locale="true">
<body bgcolor="#ffffff">
  <table border="0" width="100%">
    <tr>
      <td width="100%" height="91" colspan="2">
        <tiles:insert attribute="head"/>
      </td>
    </tr>
    <tr>
      <td width="16%" height="290">
        <tiles:insert attribute="left"/>
      </td>
      <td width="84%" height="290">
        <tiles:insert attribute="body"/>
      </td>
    </tr>
    <tr>
      <td width="100%" height="83" colspan="2">
        <tiles:insert attribute="foot"/>
      </td>
    </tr>
  </table>
</body>
</html:html>

index_body.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<center>
  <html:link href="operatorAction.do?operator=browser">
    <bean:message key="index.body.nextshow"/>
  </html:link>
</center>

index.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert definition="index-definition"/>

show_body.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/camel-define.tld" prefix="camel"%>
<html:form action="operatorAction.do" method="post">
  <bean:message key="show.body.totalrecords"/>
  <bean:write name="pageinfo" property="recordCountNumber" scope="session"/>
  &nbsp;
  <bean:message key="show.body.totalpages"/>
  <bean:write name="pageinfo" property="pageCountNumber" scope="session"/>
  &nbsp;
  <bean:message key="show.body.currentlypage"/>
  <bean:write name="pageinfo" property="currentlyPage" scope="session"/>
  &nbsp;
  <logic:greaterThan name="pageinfo" property="currentlyPage" value="1">
    <html:link href="operatorAction.do?operator=showFirstPage">
      <bean:message key="show.body.first"/>
    </html:link>
    &nbsp;
    <html:link href="operatorAction.do?operator=showPreviousPage">
      <bean:message key="show.body.previous"/>
    </html:link>
    &nbsp;
  </logic:greaterThan>
  <camel:isLastPage page="pageinfo">
    <html:link href="operatorAction.do?operator=showNextPage">
      <bean:message key="show.body.next"/>
    </html:link>
    &nbsp;
    <html:link href="operatorAction.do?operator=showLastPage">
      <bean:message key="show.body.last"/>
    </html:link>
  </camel:isLastPage>
  <br/>
  <table align="left" border="1" width="70%">
    <tr bgcolor="#COCOCO">
      <td align="center">
        <bean:message key="book.id"/>
      </td>
      <td align="center">
        <bean:message key="book.name"/>
      </td>
      <td align="center">
        <bean:message key="book.author"/>
      </td>
      <td align="center">
        <bean:message key="book.publish"/>
      </td>
      <td align="center">
        <bean:message key="book.price"/>
      </td>
      <td align="center">
        <bean:message key="book.operator"/>
      </td>
    </tr>
    <logic:iterate id="book" name="books" scope="session">
      <tr>
        <td width="10%">
          <bean:write name="book" property="bookId"/>
        </td>
        <td width="25%">
          <bean:write name="book" property="bookName"/>
        </td>
        <td width="10%">
          <bean:write name="book" property="author"/>
        </td>
        <td width="25%">
          <bean:write name="book" property="publish"/>
        </td>
        <td width="10">
          <bean:write name="book" property="price"/>
        </td>
        <td width="25%">
          <a href="operatorAction.do?operator=showModify&bookid=<bean:write name="book" property="bookId"/>">
            <bean:message key="link.modify"/>
          </a>
          &nbsp;&nbsp;
          <a href="operatorAction.do?operator=showDelete&bookid=<bean:write name="book" property="bookId"/>">
            <bean:message key="link.delete"/>
          </a>
        </td>
        <bean:define id="bookid" name="book" property="bookId"/>
        </tr>
    </logic:iterate>
  </table>
</html:form>

show.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert definition="show-definition"/>

edit_body.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<!--
  <script src="/WEB-INF/js/check.js" type="javascript"/>
  onsubmit="return check(this)"
  <html:errors/>
-->
<center>
  <html:form action="/operatorAction.do?operator=SubmitRecord" method="post">
    <logic:present name="bookBean">
      <table align="center" border="0">
        <tr>
          <td>
            <bean:message key="book.id"/>
          </td>
          <td>
            <html:text name="bookBean" property="bookId"/>
          </td>
        </tr>
        <tr>
          <td>
            <bean:message key="book.name"/>
          </td>
          <td>
            <html:text name="bookBean" property="bookName"/>
          </td>
        </tr>
        <tr>
          <td>
            <bean:message key="book.author"/>
          </td>
          <td>
            <html:text name="bookBean" property="author"/>
          </td>
        </tr>
        <tr>
          <td>
            <bean:message key="book.publish"/>
          </td>
          <td>
            <html:text name="bookBean" property="publish"/>
          </td>
        </tr>
        <tr>
          <td>
            <bean:message key="book.price"/>
          </td>
          <td>
            <html:text name="bookBean" property="price"/>
          </td>
        </tr>
        <tr>
          <td>
            <html:submit property="submit">
              <bean:message key="button.submit"/>
            </html:submit>
          </td>
          <td>
            <html:reset>
              <bean:message key="button.reset"/>
            </html:reset>
          </td>
        </tr>
      </table>
    </logic:present>
  </html:form>
</center>

editrecord.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert definition="edit-definition"/>

find_body.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<center>
  <html:form action="findRecordAction.do" method="post">
    <html:select property="findByKey">
      <html:option value="bookName">
        <bean:message key="find.jsp.findkey.bookname"/>
      </html:option>
      <html:option value="author">
        <bean:message key="find.jsp.findkey.author"/>
      </html:option>
      <html:option value="publish">
        <bean:message key="find.jsp.findkey.publish"/>
      </html:option>
    </html:select>
    <html:text property="findByValue"/>
    <br/>
    <html:submit>
      <bean:message key="find.jsp.submit"/>
    </html:submit>
  </html:form>
</center>

findrecord.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert definition="find-definition"/>

success_body.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
  <table width="50%" border="0" align="center" cellpadding="10" cellspacing="0">
    <tr>
      <td bgcolor="#A4A4A4">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td bgcolor="#FFFFFF">
              <table width="100%" border="0" cellpadding="15" cellspacing="1">
                <tr>
                  <td bgcolor="#E1E1E1">
                    <div align="center">
                      <strong>
                        <html:link href="/operatorAction.do?operator=showFirstPage">
                          <bean:message key="success.jsp.operatorerror"/>
                          <bean:message key="jsp.back"/>
                        </html:link>
                      </strong>
                    </div>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>

success.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert definition="success-definition"/>

error_body.jsp:
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
  <table width="50%" border="0" align="center" cellpadding="10" cellspacing="0">
    <tr>
      <td bgcolor="#A4A4A4">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td bgcolor="#FFFFFF">
              <table width="100%" border="0" cellpadding="15" cellspacing="1">
                <tr>
                  <td bgcolor="#E1E1E1">
                    <div align="center">
                      <strong>
                        <html:link href="/operatorAction.do?operator=showFirstPage">
                          <bean:message key="error.jsp.operatorerror"/>
                          <bean:message key="jsp.back"/>
                        </html:link>
                      </strong>
                    </div>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>

error.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert definition="error-definition"/>

以下是消息资源文件,都位于WEB-INF/classes/目录下,
中文消息资源文件ApplicationResources.properties:
head.title.welcome=\u5934\u90e8!
head.language.chinese=\u4e2d\u6587
head.language.english=\u82f1\u6587

left.title.welcome=\u5de6\u8fb9\u83dc\u5355!
left.link.index=\u9996\u9875
left.link.show=\u6d4f\u89c8\u4e66\u7c4d
left.link.addnew=\u6dfb\u52a0\u4e66\u7c4d

foot.title.welcome=\u5e95\u90e8!
foot.copyright=\u7248\u6743\u6240\u6709 @2005.5 by \u5317\u5927\u9752\u9e1f

index.body.title=\u9996\u9875\u4e3b\u4f53\u90e8\u5206!
show.body.title=\u6d4f\u89c8\u9875\u4e3b\u4f53\u90e8\u5206!

index.body.nextshow=\u6d4f\u89c8

index.jsp.lang.error=<font color=red>\u8bed\u8a00\u53c2\u6570\u9519\u8bef</font>
index.jsp.language.null=<font color=red>\u8bed\u8a00\u53c2\u6570\u4e3a\u7a7a</font>
index.jsp.operator.error=<font color=red>\u64cd\u4f5c\u53c2\u6570\u9519\u8bef</font>
index.jsp.operator.null=<font color=red>\u64cd\u4f5c\u53c2\u6570\u4e3a\u7a7a</font>

link.delete=\u5220\u9664
link.modify=\u4fee\u6539

book.id=\u4e66\u53f7
book.name=\u4e66\u540d
book.author=\u4f5c\u8005
book.publish=\u51fa\u7248\u793e
book.price=\u5355\u4ef7
book.operator=\u64cd\u4f5c
button.submit=\u63d0\u4ea4
button.reset=\u91cd\u7f6e
button.cacel=\u53d6\u6d88

show.body.totalrecords=\u603b\u8bb0\u5f55\u6570:
show.body.totalpages=\u603b\u9875\u6570:
show.body.currentlypage=\u5f53\u524d\u9875\u7801:
show.body.first=\u6700\u524d\u9875
show.body.previous=\u4e0a\u4e00\u9875
show.body.next=\u4e0b\u4e00\u9875
show.body.last=\u6700\u540e\u9875

book.bookid.error=\u4e66\u53f7\u4e3a\u7a7a\u6216\u9519\u8bef!
book.bookname.error=\u4e66\u540d\u4e3a\u7a7a\u6216\u9519\u8bef!
book.author.error=\u4f5c\u8005\u4e3a\u7a7a\u6216\u9519\u8bef!
book.publish.error=\u51fa\u7248\u793e\u4e3a\u7a7a\u6216\u9519\u8bef!
book.price.error=\u5355\u4ef7\u4e3a\u7a7a\u6216\u9519\u8bef!
editrecord.jsp.adderror=\u6dfb\u52a0\u8bb0\u5f55\u672a\u6210\u529f!
editrecord.jsp.modifyerror=\u4fee\u6539\u8bb0\u5f55\u672a\u6210\u529f!
editrecord.jsp.deleteerror=\u5220\u9664\u8bb0\u5f55\u672a\u6210\u529f!
editrecord.body.title=\u7f16\u8f91\u9875\u9762\u4e3b\u4f53!

edit.body.error=\u975e\u6cd5\u64cd\u4f5c!

error.jsp.operatorerror=\u64cd\u4f5c\u9519\u8bef!

left.link.findbykey=\u81ea\u5b9a\u4e49\u67e5\u8be2
find.jsp.error=<font color=red>\u8bf7\u9009\u62e9\u548c\u586b\u5199\u67e5\u8be2\u53c2\u6570!</font>
find.jsp.submit=\u67e5\u627e
find.jsp.findkey.bookname=\u4e66\u540d\u79f0
find.jsp.findkey.author=\u4f5c\u8005
find.jsp.findkey.publish=\u51fa\u7248\u793e
success.jsp.operatorerror=\u64cd\u4f5c\u6210\u529f
jsp.back=\u8fd4\u56de\u4e3b\u9875\u9762
findrecord.jsp.notfound=\u672a\u67e5\u627e\u5230\u76f8\u5173\u8bb0\u5f55!

英文消息资源文件ApplicationResources_en.properties:
head.title.welcome=Head!
head.language.chinese=Chinese
head.language.english=English

left.title.welcome=Welcome Left!
left.link.index=Index
left.link.show=Browse Book
left.link.addnew=Add New Book

foot.title.welcome=Welcome foot!
foot.copyright=Copyright @2005.5 by Camel

index.body.title=Welcome index body!
show.body.title=Welcome browser body!

index.body.nextshow=SHOW

index.jsp.lang.error=<font color=red>Language Error</font>
index.jsp.language.null=<font color=red>Language Null</font>
index.jsp.operator.error=<font color=red>Operator Error</font>
index.jsp.operator.null=<font color=red>Operator Null</font>

link.delete=DELETE
link.modify=MODIFY

book.id=ID
book.name=BOOK NAME
book.author=AUTHOR
book.publish=PUBLISH
book.price=PRICE
book.operator=OPERATOR
button.submit=Submit
button.reset=Reset
button.cancel=Cancel

show.body.totalrecords=Total Records:
show.body.totalpages=Total Pages:
show.body.currentlypage=Currently Page:
show.body.first=First
show.body.previous=Previous
show.body.next=Next
show.body.last=Last

book.bookid.error=BookID is null or error!
book.bookname.error=BookName is null or error!
book.author.error=Author is null or error!
book.publish.error=Publish is null or error!
book.price.error=Price is null or not number!

editrecord.jsp.adderror=Add Record Error!
editrecord.jsp.modifyerror=Modify Record Error!
editrecord.jsp.deleteerror=Delete Record Error!
editrecord.body.title=Welcome Edit page body!

edit.body.error=Invalid Operator!

error.jsp.operatorerror=Operator error
jsp.back=Back main page
left.link.findbykey=Custom Find
find.jsp.error=<font color=red>Please select find key and input value!</font>
find.jsp.submit=Find
find.jsp.findkey.bookname=BookName
find.jsp.findkey.author=Author
find.jsp.findkey.publish=Publish
success.jsp.operatorerror=Operator success
jsp.back=Back main page
findrecord.jsp.notfound=It's nothing to found!

我使用的是MySQL4.0数据库,驱动程序为:mm.mysql-2.0.14-bin.jar,数据脚本bookshop如下:
create database bookshop;
use bookshop;
create table booktab
(bookid   varchar(20) primary key not null,
 bookname varchar(50) not null default '',
 author   varchar(50) not null default '',
 publish  varchar(50) not null default '',
 price    varchar(20) not null default 0.00);
测试记录集由大家去Insert20多条吧。

因为这个论坛我不能上传附件,所以只好把代码一个一个的贴上来,我现在在一家小公司做事,工作中体会最深的是,对于应用软件项目来说,最重要的是客户的需求,使用什么技术不是最重要的,所以想和大家说一下,不要执迷于技术。对于一个软件项目,编写代码只占整个开发周期的20%,甚至更低。大部分的时间是在围绕客户需求做功能测试。能够写出上面的代码,对于一个程序员只能说只是达到了最基本的要求,对于一个程序员来说,最重要的是执着,耐心和锲而不舍。最后写上这些废话和大家共勉。如果有问题可以找我一起探讨,我的QQ:38065558。

本文地址:http://com.8s8s.com/it/it9753.htm