AfficheAction.java
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:5k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.webtier;
  2. import org.apache.struts.action.*;
  3. import javax.servlet.http.*;
  4. import com.domain.AfficheForm;
  5. import com.dao.AfficheDao;
  6. import java.util.List;
  7. import com.tool.Chinese;
  8. //公告信息的Action
  9. public class AfficheAction
  10.     extends Action {
  11.   private AfficheDao dao = null;
  12.   private int action;
  13.   public ActionForward execute(ActionMapping mapping,
  14.                                ActionForm form,
  15.                                HttpServletRequest request,
  16.                                HttpServletResponse response) {
  17.     dao = new AfficheDao();
  18.     this.action = Integer.parseInt(request.getParameter("action"));
  19.     switch (action) {
  20.       case 0: {
  21.         return afficheSelect(mapping, form, request, response); //对公告信息全部查询功能
  22.       }
  23.       case 1: {
  24.         return afficheForward(mapping, form, request, response); //通过方法转向添加信息的网页
  25.       }
  26.       case 2: {
  27.         return afficheInsert(mapping, form, request, response); //添加公告信息
  28.       }
  29.       case 3: {
  30.         return afficheDelete(mapping, form, request, response); //以数据库流水号为条件删除公告信息
  31.       }
  32.       case 4: {
  33.         return afficheSelectOne(mapping, form, request, response); //以数据库流水号为条件查询公告信息
  34.       }
  35.       case 5: {
  36.         return afficheUpdate(mapping, form, request, response); //以数据库流水号为条件修改公告信息
  37.       }
  38.       case 6: {
  39.       return afficheContent(mapping, form, request, response);   //以数据库流水号为条件查询公告信息的内容
  40.     }
  41.     }
  42.     throw new java.lang.UnsupportedOperationException(
  43.         "Method $execute() not yet implemented.");
  44.   }
  45.   //以数据库流水号为条件查询公告信息的内容
  46.   public ActionForward afficheContent(ActionMapping mapping, ActionForm form,
  47.                                        HttpServletRequest request,
  48.                                        HttpServletResponse response){
  49.    request.setAttribute("affiche",dao.selectOneAffiche(Integer.valueOf(request.getParameter("id"))));
  50.    return mapping.findForward("afficheContent");
  51.   }
  52.       //以数据库流水号为条件查询公告信息
  53.       public ActionForward afficheSelectOne(ActionMapping mapping,
  54.                                             ActionForm form,
  55.                                             HttpServletRequest request,
  56.                                             HttpServletResponse response) {
  57.     request.setAttribute("affiche",
  58.                          dao.selectOneAffiche(Integer.valueOf(request.
  59.         getParameter("id"))));
  60.     return mapping.findForward("afficheSelectOne");
  61.   }
  62.   //以数据库流水号为条件修改公告信息
  63.   public ActionForward afficheUpdate(ActionMapping mapping, ActionForm form,
  64.                                      HttpServletRequest request,
  65.                                      HttpServletResponse response) {
  66.     AfficheForm afficheForm = (AfficheForm) form;
  67.     afficheForm.setName(Chinese.chinese(request.getParameter("name")));
  68.     afficheForm.setContent(Chinese.chinese(request.getParameter("content")));
  69.     afficheForm.setId(Integer.valueOf(request.getParameter("id")));
  70.     dao.updateAffiche(afficheForm);
  71.     request.setAttribute("success", "修改公告信息成功!!!");
  72.     return mapping.findForward("afficheOperation");
  73.   }
  74.   //对公告信息的全部查询功能
  75.   public ActionForward afficheSelect(ActionMapping mapping, ActionForm form,
  76.                                      HttpServletRequest request,
  77.                                      HttpServletResponse response) {
  78.     List list = dao.selectAffiche();
  79.     int pageNumber = list.size(); //计算出有多少条记录
  80.     int maxPage = pageNumber; //计算有多少页数
  81.     String number = request.getParameter("i");
  82.     if (maxPage % 7 == 0) {
  83.       maxPage = maxPage / 7;
  84.     }
  85.     else {
  86.       maxPage = maxPage / 7 + 1;
  87.     }
  88.     if (number == null) {
  89.       number = "0";
  90.     }
  91.     request.setAttribute("number", String.valueOf(number));
  92.     request.setAttribute("maxPage", String.valueOf(maxPage));
  93.     request.setAttribute("pageNumber", String.valueOf(pageNumber));
  94.     request.setAttribute("list", list);
  95.     return mapping.findForward("afficheSelect");
  96.   }
  97.   //通过方法转向添加信息的网页
  98.   public ActionForward afficheForward(ActionMapping mapping, ActionForm form,
  99.                                       HttpServletRequest request,
  100.                                       HttpServletResponse response) {
  101.     return mapping.findForward("afficheForward");
  102.   }
  103.   //添加公告信息
  104.   public ActionForward afficheInsert(ActionMapping mapping, ActionForm form,
  105.                                      HttpServletRequest request,
  106.                                      HttpServletResponse response) {
  107.     AfficheForm afficheForm = (AfficheForm) form;
  108.     afficheForm.setName(Chinese.chinese(request.getParameter("name")));
  109.     afficheForm.setContent(Chinese.chinese(request.getParameter("content")));
  110.     dao.insertAffiche(afficheForm);
  111.     request.setAttribute("success", "添加公告信息成功!!!");
  112.     return mapping.findForward("afficheOperation");
  113.   }
  114.   //以数据库流水号为条件删除公告信息
  115.   public ActionForward afficheDelete(ActionMapping mapping, ActionForm form,
  116.                                      HttpServletRequest request,
  117.                                      HttpServletResponse response) {
  118.     dao.deleteAffiche(Integer.valueOf(request.getParameter("id")));
  119.     request.setAttribute("success", "删除公告信息成功");
  120.     return mapping.findForward("afficheOperation");
  121.   }
  122. }