⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 departmentactions.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/*
 * DepartmentActions.java
 *
 * Created on 2006年5月30日, 上午4:09
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package enova.web.struts.action;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import enova.service.*;
import enova.pojo.*;
import enova.util.Const;

/**
 *
 * @author vlinux
 */
public class DepartmentActions extends DispatchAction {
    
    private String name;
    private Integer id;
    private DepartmentService ds = (DepartmentService)ServiceFactory.makeService("DepartmentService");
    
    private void loadForm(javax.servlet.http.HttpServletRequest request){
        this.name = request.getParameter("name");
        try{
            int intId = Integer.parseInt(request.getParameter("id"));
            this.id = new Integer(intId);
        }catch(Exception e){
            this.id = null;
        }
    }
    
    //添加学院
    public ActionForward add(ActionMapping mapping, ActionForm actionForm,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if( this.verifyRoot(request) )
            return mapping.findForward(Const.ACCESS_DENY);
        try{
            loadForm(request);
            Department d = new Department(name);
            ds.updateOrCreate(d);
            request.setAttribute("department",d);
        }catch(StoreException se){
            request.setAttribute(Const.MESSAGES,"数据库出错");
            return mapping.findForward(Const.STORE_EXCEPTION);
        }catch(UniqueException ue){
            request.setAttribute(Const.MESSAGES,"该学院名称已经存在");
            return mapping.findForward(Const.ADD);
        }
        request.setAttribute(Const.MESSAGES,"创建成功");
        return mapping.findForward(Const.ADD);
    }
    
    //查看所有学院
    public ActionForward view(ActionMapping mapping, ActionForm actionForm,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if( this.verifyRoot(request) )
            return mapping.findForward(Const.ACCESS_DENY);
        try{
            request.setAttribute("departments",ds.getAll());
        }catch(StoreException se){
            request.setAttribute(Const.MESSAGES,"数据库出错");
            return mapping.findForward(Const.STORE_EXCEPTION);
        }
        return mapping.findForward(Const.VIEW);
    }
    
    //根据ID删除一个学院
    public ActionForward delete(ActionMapping mapping, ActionForm actionForm,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if( this.verifyRoot(request) )
            return mapping.findForward(Const.ACCESS_DENY);
        try{
            loadForm(request);
            ds.delete(id);
        }catch(StoreException se){
            request.setAttribute(Const.MESSAGES,"数据库出错");
            return mapping.findForward(Const.STORE_EXCEPTION);
        }catch(NotExistException nee){
            request.setAttribute(Const.MESSAGES,"记录不存在");
            return mapping.findForward(Const.VIEW);
        }finally{
            try{
                request.setAttribute("departments",ds.getAll());
            }catch(StoreException se){
                request.setAttribute(Const.MESSAGES,"数据库出错");
                return mapping.findForward(Const.STORE_EXCEPTION);
            }
        }
        return mapping.findForward(Const.VIEW);
    }
    
    //通过ID获取学院信息
    public ActionForward get(ActionMapping mapping, ActionForm actionForm,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if( this.verifyRoot(request) )
            return mapping.findForward(Const.ACCESS_DENY);
        try{
            loadForm(request);
            request.setAttribute("department",ds.get(id));
        }catch(StoreException se){
            request.setAttribute(Const.MESSAGES,"数据库出错");
            return mapping.findForward(Const.STORE_EXCEPTION);
        }
        return mapping.findForward(Const.UPDATE);
    }
    
    //修改学院信息
    public ActionForward update(ActionMapping mapping, ActionForm actionForm,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if( this.verifyRoot(request) )
            return mapping.findForward(Const.ACCESS_DENY);
        try{
            loadForm(request);
            Department d = new Department(id);
            d.setName(name);
            ds.updateOrCreate(d);
        }catch(StoreException se){
            request.setAttribute(Const.MESSAGES,"数据库出错");
            return mapping.findForward(Const.STORE_EXCEPTION);
        }catch(UniqueException ue){
            request.setAttribute(Const.MESSAGES,"学院名称已经存在");
            return mapping.findForward(Const.UPDATE);
        }finally{
            try{
                request.setAttribute("department",ds.get(id));
            }catch(StoreException se){
                request.setAttribute(Const.MESSAGES,"数据库出错");
                return mapping.findForward(Const.STORE_EXCEPTION);
            }
        }
        request.setAttribute(Const.MESSAGES,"修改成功");
        return mapping.findForward(Const.UPDATE);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -