LinkAction.java~37~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:6k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import com.chinacannel.xlchemical.service.LinkService;
- import org.apache.struts.actions.DispatchAction;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.chinacannel.entity.Link;
- import java.util.List;
- import com.chinacannel.xlchemical.struts.ActionForm.LinkActionForm;
- import com.chinacannel.common.PageInfo;
- import com.chinacannel.common.ImageUpload;
- import com.chinacannel.entity.Image;
- public class LinkAction extends DispatchAction {
- LinkService ls = new LinkService();
- public ActionForward EditLink(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- LinkActionForm laf = (LinkActionForm) actionForm;
- Link link = new Link();
- String Message = "";
- ImageUpload iu = new ImageUpload();
- Image image = new Image();
- boolean b = false;
- try {
- ls.beginTran();
- if (!laf.getLinkID().equals(new Long(0))) {
- link = ls.GetLinkById(laf.getLinkID());
- }
- link.setLin_CName(laf.getCName());
- link.setLin_EName(laf.getEName());
- link.setLin_Url(laf.getUrl());
- link.setLin_Type(laf.getType());
- if(laf.getLinkImg().getFileSize()>0){
- if(!laf.getImageID().equals(new Long(0))){
- iu.deleteImage(laf.getImageID().intValue());
- }
- image = iu.saveImage(laf.getLinkImg(), servletRequest, false);
- pro.setImage(image);
- }
- if(!laf.getLinkID().equals(new Long(0))){
- b = ls.UpdateLink(link);
- Message = "更新成功,请返回!";
- }else{
- b = ls.AddLink(link);
- Message = "添加成功,请返回!";
- }
- ls.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ls.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if(b == false){
- Message = "添加失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", "/Manage/Link.do?todo=OpenLink");
- return actionMapping.findForward("EditLink");
- }
- public ActionForward OpenLink(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- List linkList = null;
- String title = "链接管理";
- Long linkID = new Long(0);
- Link link = new Link();
- try {
- if (servletRequest.getParameter("LinkID") != null) {
- linkID = new Long(servletRequest.getParameter("LinkID"));
- }
- ls.beginTran();
- linkList = ls.GetAllLink();
- link = ls.GetLinkById(linkID);
- ls.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ls.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("link", link);
- servletRequest.setAttribute("title", title);
- servletRequest.setAttribute("linkList", linkList);
- return actionMapping.findForward("OpenLink");
- }
- public ActionForward DeleteLink(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Long linID = new Long(0);
- Link link = null;
- String Message = "";
- try {
- linID = new Long(servletRequest.getParameter("linID"));
- ls.beginTran();
- link = ls.GetLinkById(linID);
- ls.DeleteLink(link);
- Message = "删除成功,请返回!";
- ls.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ls.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", "/Manage/Link.do?todo=OpenLink");
- return actionMapping.findForward("DeleteLink");
- }
- public ActionForward ShowLink(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- int pageNo = 0;
- PageInfo pageInfo = null;
- try {
- pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
- } catch (Exception ex1) {}
- try {
- ls.beginTran();
- pageInfo = ls.getPageInfo(new Long(3), pageNo);
- ls.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ls.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("pageInfo", pageInfo);
- return actionMapping.findForward("ShowLink");
- }
- }