LinkAction.java~32~
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:6k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import com.chinacannel.xlchemical.service.LinkService;
  3. import org.apache.struts.actions.DispatchAction;
  4. import org.apache.struts.action.ActionMapping;
  5. import org.apache.struts.action.ActionForward;
  6. import org.apache.struts.action.ActionForm;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.chinacannel.entity.Link;
  10. import java.util.List;
  11. import com.chinacannel.xlchemical.struts.ActionForm.LinkActionForm;
  12. import com.chinacannel.common.PageInfo;
  13. import com.chinacannel.common.ImageUpload;
  14. public class LinkAction extends DispatchAction {
  15.     LinkService ls = new LinkService();
  16.     public ActionForward EditLink(ActionMapping actionMapping,
  17.                                   ActionForm actionForm,
  18.                                   HttpServletRequest servletRequest,
  19.                                   HttpServletResponse servletResponse) {
  20.         LinkActionForm laf = (LinkActionForm) actionForm;
  21.         Link link = new Link();
  22.         String Message = "";
  23.         ImageUpload iu = new ImageUpload();
  24.         boolean b = false;
  25.         try {
  26.             ls.beginTran();
  27.             if (!laf.getLinkID().equals(new Long(0))) {
  28.                 link = ls.GetLinkById(laf.getLinkID());
  29.             }
  30.             link.setLin_CName(laf.getCName());
  31.             link.setLin_EName(laf.getEName());
  32.             link.setLin_Url(laf.getUrl());
  33.             link.setLin_Type(laf.getType());
  34.             if(laf.getLinkImg().getFileSize()>0){
  35.                 if(!laf.getImageID().equals(new Long(0))){
  36.                 }
  37.             }
  38.             if(!laf.getLinkID().equals(new Long(0))){
  39.                 b = ls.UpdateLink(link);
  40.                 Message = "更新成功,请返回!";
  41.             }else{
  42.                 b = ls.AddLink(link);
  43.                 Message = "添加成功,请返回!";
  44.             }
  45.             ls.commit();
  46.         } catch (Exception ex) {
  47.             log.error(ex.getMessage(), ex);
  48.             try {
  49.                 ls.rollback();
  50.             } catch (Exception ex2) {
  51.                 log.error(ex2.getMessage(), ex2);
  52.             }
  53.         }
  54.         if(b == false){
  55.             Message = "添加失败,请返回!";
  56.         }
  57.         servletRequest.setAttribute("Message", Message);
  58.         servletRequest.setAttribute("Url", "/Manage/Link.do?todo=OpenLink");
  59.         return actionMapping.findForward("EditLink");
  60.     }
  61.     public ActionForward OpenLink(ActionMapping actionMapping,
  62.                                   ActionForm actionForm,
  63.                                   HttpServletRequest servletRequest,
  64.                                   HttpServletResponse servletResponse) {
  65.         List linkList = null;
  66.         String title = "链接管理";
  67.         Long linkID = new Long(0);
  68.         Link link = new Link();
  69.         try {
  70.             if (servletRequest.getParameter("LinkID") != null) {
  71.                 linkID = new Long(servletRequest.getParameter("LinkID"));
  72.             }
  73.             ls.beginTran();
  74.             linkList = ls.GetAllLink();
  75.             link = ls.GetLinkById(linkID);
  76.             ls.commit();
  77.         } catch (Exception ex) {
  78.             log.error(ex.getMessage(), ex);
  79.             try {
  80.                 ls.rollback();
  81.             } catch (Exception ex2) {
  82.                 log.error(ex2.getMessage(), ex2);
  83.             }
  84.         }
  85.         servletRequest.setAttribute("link", link);
  86.         servletRequest.setAttribute("title", title);
  87.         servletRequest.setAttribute("linkList", linkList);
  88.         return actionMapping.findForward("OpenLink");
  89.     }
  90.     public ActionForward DeleteLink(ActionMapping actionMapping,
  91.                                     ActionForm actionForm,
  92.                                     HttpServletRequest servletRequest,
  93.                                     HttpServletResponse servletResponse) {
  94.         Long linID = new Long(0);
  95.         Link link = null;
  96.         String Message = "";
  97.         try {
  98.             linID = new Long(servletRequest.getParameter("linID"));
  99.             ls.beginTran();
  100.             link = ls.GetLinkById(linID);
  101.             ls.DeleteLink(link);
  102.             Message = "删除成功,请返回!";
  103.             ls.commit();
  104.         } catch (Exception ex) {
  105.             log.error(ex.getMessage(), ex);
  106.             try {
  107.                 ls.rollback();
  108.             } catch (Exception ex2) {
  109.                 log.error(ex2.getMessage(), ex2);
  110.             }
  111.         }
  112.         servletRequest.setAttribute("Message", Message);
  113.         servletRequest.setAttribute("Url", "/Manage/Link.do?todo=OpenLink");
  114.         return actionMapping.findForward("DeleteLink");
  115.     }
  116.     public ActionForward ShowLink(ActionMapping actionMapping,
  117.                                   ActionForm actionForm,
  118.                                   HttpServletRequest servletRequest,
  119.                                   HttpServletResponse servletResponse) {
  120.         int pageNo = 0;
  121.         PageInfo pageInfo = null;
  122.         try {
  123.             pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
  124.         } catch (Exception ex1) {}
  125.         try {
  126.             ls.beginTran();
  127.             pageInfo = ls.getPageInfo(new Long(3), pageNo);
  128.             ls.commit();
  129.         } catch (Exception ex) {
  130.             log.error(ex.getMessage(), ex);
  131.             try {
  132.                 ls.rollback();
  133.             } catch (Exception ex2) {
  134.                 log.error(ex2.getMessage(), ex2);
  135.             }
  136.         }
  137.         servletRequest.setAttribute("pageInfo", pageInfo);
  138.         return actionMapping.findForward("ShowLink");
  139.     }
  140. }