PageCtrlAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package BookStore;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.Action;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.ActionMapping;
  8. import org.apache.struts.action.ActionMessage;
  9. import org.apache.struts.action.ActionMessages;
  10. import javax.servlet.ServletContext;
  11. import javax.sql.DataSource;
  12. import java.sql.Connection;
  13. import javax.servlet.http.*;
  14. import java.util.*;
  15. import org.apache.struts.action.DynaActionForm;
  16. public final class PageCtrlAction extends Action{  
  17. public ActionForward execute(
  18. ActionMapping mapping,
  19. ActionForm form,
  20. HttpServletRequest request,  
  21. HttpServletResponse response) throws Exception {
  22. DynaActionForm pageIdForm = (DynaActionForm) form;         
  23. Integer pageId = (Integer)pageIdForm.get("pageId");
  24. int iPageId = 0;
  25. if (pageId!=null) iPageId = pageId.intValue();
  26. if (iPageId<0) iPageId = 0;
  27.     ServletContext context = servlet.getServletContext();
  28. DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  29.         DB db = new DB(dataSource);
  30.         HttpSession session = request.getSession(true);
  31. Vector bookList = new Vector();
  32. SearchStatus schSta = new SearchStatus();
  33. schSta = (SearchStatus)session.getAttribute(Constants.BOOK_SEARCH_STATUS_KEY);
  34. String PageForward;
  35. ActionMessages errors = new ActionMessages();
  36. if (schSta.getBookCount()==0){
  37.    PageForward="toBookMain";  
  38.         }
  39.         else
  40.         if (schSta.getBookCount()<iPageId * Constants.BOOK_PAGE_SIZE + 1){
  41.          iPageId--;
  42.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  43.                            new ActionMessage("errors.pageEnd"));
  44. if (!errors.isEmpty()) {
  45. saveErrors(request, errors);
  46.   PageForward="toWrong";  
  47. }
  48. else{
  49. schSta.setPageId(iPageId);
  50. bookList = Book.SearchBook(db,schSta.getMode(),schSta.getCatId(),schSta.getField(),schSta.getKey());
  51. session.setAttribute(Constants.BOOK_LIST_KEY,bookList);
  52. session.setAttribute(Constants.BOOK_SEARCH_STATUS_KEY,schSta);
  53.    PageForward="toBookMain";  
  54.        }
  55.         
  56. db.close();
  57.      return  mapping.findForward(PageForward);  
  58. }
  59. }