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

Java编程

开发平台:

Java

  1. package BookStore;
  2. import javax.sql.DataSource;
  3. import java.sql.Connection;
  4. import javax.servlet.ServletContext;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import org.apache.struts.action.Action;
  9. import org.apache.struts.action.ActionForm;
  10. import org.apache.struts.action.ActionForward;
  11. import org.apache.struts.action.ActionMapping;
  12. import org.apache.struts.action.ActionMessage;
  13. import org.apache.struts.action.ActionMessages;
  14. import java.util.Vector;
  15. import org.apache.struts.action.DynaActionForm;
  16. public final class FirstAction extends Action{  
  17. public ActionForward execute(
  18. ActionMapping mapping,
  19. ActionForm form,
  20. HttpServletRequest request,  
  21. HttpServletResponse response) throws Exception {
  22.     DynaActionForm bookSearchForm = (DynaActionForm) form;         
  23. Integer mode = null;
  24. Integer bookCatId = null;
  25. String key = null;
  26. String field = null;
  27. if (bookSearchForm!=null){
  28. mode = (Integer)bookSearchForm.get("mode");
  29. bookCatId = (Integer)bookSearchForm.get("bookCatId");
  30. key = (String)bookSearchForm.get("key");
  31. field = (String)bookSearchForm.get("field");
  32. }
  33.     ServletContext context = servlet.getServletContext();
  34. DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  35.         DB db = new DB(dataSource);
  36.         
  37. SearchStatus schSta = new SearchStatus();
  38. int iMode = mode.intValue();
  39. schSta.setMode(iMode);
  40. int iCatId=0; 
  41. if (iMode==0){
  42. iCatId = BookCat.GetFirstBookCat(db);
  43. schSta.setCatId(iCatId);
  44. }
  45. else if (iMode==1){
  46. iCatId= bookCatId.intValue();
  47. schSta.setCatId(iCatId);
  48. }
  49. else if (iMode==2){
  50. schSta.setKey(key);
  51. schSta.setField(field);
  52. }
  53.         int bookCount = Book.GetBookCount(db);
  54. int iPageCount;
  55. if (bookCount%Constants.BOOK_PAGE_SIZE==0) {
  56. iPageCount = bookCount/Constants.BOOK_PAGE_SIZE;
  57. }
  58. else{
  59. iPageCount = bookCount/Constants.BOOK_PAGE_SIZE+1;
  60. }
  61. schSta.setBookCount(bookCount);
  62. schSta.setPageCount(iPageCount);
  63.         Vector bookList = new Vector();
  64.         HttpSession session = request.getSession();
  65.         
  66. session.setAttribute(Constants.BOOK_CAT_LIST_KEY,BookCat.Search(db));
  67. bookList = Book.SearchBook(db,iCatId,field,key);
  68. session.setAttribute(Constants.BOOK_LIST_KEY,bookList);
  69. session.setAttribute(Constants.BOOK_SEARCH_STATUS_KEY,schSta);
  70. db.close();
  71.     return (mapping.findForward("toBookMain"));
  72.   }
  73. }