LookNoteAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:3k
- package StudyNote;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionMessage;
- import org.apache.struts.action.ActionMessages;
- import javax.servlet.ServletContext;
- import javax.sql.DataSource;
- import java.sql.Connection;
- import javax.servlet.http.*;
- import java.util.*;
- import org.apache.struts.action.DynaActionForm;
- public final class LookNoteAction extends Action{
- public ActionForward execute(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws Exception {
-
- DynaActionForm pageIdForm = (DynaActionForm) form;
- Integer pageId = (Integer)pageIdForm.get("pageId");
- int iPageId = 0;
- if (pageId!=null) iPageId = pageId.intValue();
- if (iPageId<0) iPageId = 0;
- ServletContext context = servlet.getServletContext();
- DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
-
- DB db = new DB(dataSource);
- HttpSession session = request.getSession(true);
- Vector noteList = new Vector();
- int noteCount = Note.GetNoteCount(db);
- int iPageCount;
- if (noteCount%Constants.NOTE_PAGE_SIZE==0) {
- iPageCount = noteCount/Constants.NOTE_PAGE_SIZE;
- }
- else{
- iPageCount = noteCount/Constants.NOTE_PAGE_SIZE+1;
- }
- String PageForward;
- ActionMessages errors = new ActionMessages();
-
-
- String username=(String)session.getAttribute(Constants.LOGIN_USERNAME_KEY);
-
- if (username==null){
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("errors.accessDeny"));
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- PageForward="toWrong";
- }
- else if (noteCount==0){
- session.setAttribute(Constants.NOTE_LIST_KEY,noteList);
- session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(iPageId));
- session.setAttribute(Constants.NOTE_PAGE_COUNT_KEY,new Integer(iPageCount));
- PageForward="toNoteMain";
- }
- else if (noteCount<iPageId * Constants.NOTE_PAGE_SIZE + 1){
- iPageId--;
- errors.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("errors.pageEnd"));
- if (!errors.isEmpty()) {
- saveErrors(request, errors);
- }
- PageForward="toWrong";
- }
- else{
- noteList = Note.SearchNoteTitle(db,iPageId);
- session.setAttribute(Constants.NOTE_LIST_KEY,noteList);
- session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(iPageId));
- session.setAttribute(Constants.NOTE_PAGE_COUNT_KEY,new Integer(iPageCount));
- PageForward="toNoteMain";
- }
-
- db.close();
- return mapping.findForward(PageForward);
- }
- }