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

Java编程

开发平台:

Java

  1. package StudyNote;
  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 LookNoteAction 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 noteList = new Vector();
  32.         int noteCount = Note.GetNoteCount(db);
  33. int iPageCount;
  34. if (noteCount%Constants.NOTE_PAGE_SIZE==0) {
  35. iPageCount = noteCount/Constants.NOTE_PAGE_SIZE;
  36. }
  37. else{
  38. iPageCount = noteCount/Constants.NOTE_PAGE_SIZE+1;
  39. }
  40. String PageForward;
  41. ActionMessages errors = new ActionMessages();
  42.     String username=(String)session.getAttribute(Constants.LOGIN_USERNAME_KEY);
  43.         
  44. if (username==null){
  45.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  46.                            new ActionMessage("errors.accessDeny"));
  47. if (!errors.isEmpty()) {
  48. saveErrors(request, errors);
  49.   PageForward="toWrong";  
  50. }
  51.         else if (noteCount==0){
  52. session.setAttribute(Constants.NOTE_LIST_KEY,noteList);
  53. session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(iPageId));
  54. session.setAttribute(Constants.NOTE_PAGE_COUNT_KEY,new Integer(iPageCount));
  55.    PageForward="toNoteMain";  
  56.         }
  57.         else if (noteCount<iPageId * Constants.NOTE_PAGE_SIZE + 1){
  58.          iPageId--;
  59.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  60.                            new ActionMessage("errors.pageEnd"));
  61. if (!errors.isEmpty()) {
  62. saveErrors(request, errors);
  63.   PageForward="toWrong";  
  64. }
  65. else{
  66. noteList = Note.SearchNoteTitle(db,iPageId);
  67. session.setAttribute(Constants.NOTE_LIST_KEY,noteList);
  68. session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(iPageId));
  69. session.setAttribute(Constants.NOTE_PAGE_COUNT_KEY,new Integer(iPageCount));
  70.    PageForward="toNoteMain";  
  71.        }
  72.         
  73. db.close();
  74.      return  mapping.findForward(PageForward);  
  75. }
  76. }