NoteManage.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.ActionForm;
  5. import org.apache.struts.action.ActionForward;
  6. import org.apache.struts.action.ActionMapping;
  7. import org.apache.struts.action.ActionMessage;
  8. import org.apache.struts.action.ActionMessages;
  9. import com.laoer.comm.web.PageList;
  10. import com.laoer.comm.web.Pages;
  11. import com.opensource.blog.exception.BlogException;
  12. import com.opensource.blog.model.Note;
  13. import com.opensource.blog.service.NoteService;
  14. import com.opensource.blog.web.form.NoteManageForm;
  15. import com.opensource.blog.web.servlet.UserSession;
  16. public class NoteManage
  17.     extends BaseAction {
  18.   private NoteService noteService;
  19.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  20.                                HttpServletRequest servletRequest,
  21.                                HttpServletResponse servletResponse) {
  22.     NoteManageForm form = (NoteManageForm) actionForm;
  23.     ActionMessages errors = new ActionMessages();
  24.     UserSession us = this.getUserSession(servletRequest);
  25.     if (form.getAction().equals("list")) {
  26.       Pages pages = new Pages(servletRequest.getLocale());
  27.       pages.setPage(form.getPage());
  28.       pages.setPerPageNum(us.getBlog().getPerartnum());
  29.       pages.setStyle(1);
  30.       pages.setFileName("noteManage.do?action=" + form.getAction());
  31.       PageList pl = this.getNoteService().findNotesByBlogID(us.getBlog().getId().longValue(), pages);
  32.       servletRequest.setAttribute("pl", pl);
  33.       return actionMapping.findForward("notemanage");
  34.     }
  35.     if (form.getAction().equalsIgnoreCase("del")) {
  36.       Note note = this.getNoteService().findNoteByID_BlogID(form.getNoteid(),
  37.           us.getBlog().getId().longValue());
  38.       if (note != null) {
  39.         try {
  40.           this.getNoteService().removeNote(note);
  41.           return new ActionForward("/noteManage.do?action=list", true);
  42.         }
  43.         catch (BlogException ex) {
  44.           errors.add("error.note.del.error", new ActionMessage("error.note.del.error"));
  45.           saveErrors(servletRequest, errors);
  46.           return actionMapping.findForward("error");
  47.         }
  48.       }
  49.     }
  50.     return actionMapping.findForward("error");
  51.   }
  52.   public NoteService getNoteService() {
  53.     return noteService;
  54.   }
  55.   public void setNoteService(NoteService noteService) {
  56.     this.noteService = noteService;
  57.   }
  58. }