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

📄 courseactions.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * CourseActions.java * * Created on 2006年6月6日, 下午11:46 * * 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 CourseActions extends DispatchAction {        private Integer id;    private String name;//    private Integer teacherId;//    private Integer hour;    private Float credit;//    private Integer year;//    private String term;//    private String examMode;    private String examType;    private String type;    private CourseService cs = (CourseService)ServiceFactory.makeService("CourseService");        private void loadForm(javax.servlet.http.HttpServletRequest request){        this.name = request.getParameter("name");        this.term = request.getParameter("term");        this.examMode = request.getParameter("examMode");        this.examType = request.getParameter("examType");        this.type = request.getParameter("type");        try{            int intId = Integer.parseInt(request.getParameter("id"));            this.id = new Integer(intId);        }catch(Exception e){            this.id = null;        }        try{            int intTeacherId = Integer.parseInt(request.getParameter("teacherId"));            this.teacherId = new Integer(intTeacherId);        }catch(Exception e){            this.teacherId = null;        }        try{            int intYear = Integer.parseInt(request.getParameter("year"));            this.year = new Integer(intYear);        }catch(Exception e){            this.year = null;        }        try{            int intHour = Integer.parseInt(request.getParameter("hour"));            this.hour = new Integer(intHour);        }catch(Exception e){            this.hour = null;        }        try{            float floatCredit = Float.parseFloat(request.getParameter("credit"));            this.credit = new Float(floatCredit);        }catch(Exception e){            this.credit = 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);            Course c = new Course(name,credit,year,term,teacherId);            c.setHour(hour);            c.setExamMode(examMode);            c.setExamType(examType);            c.setType(type);            cs.updateOrCreate(c);        }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 delete(ActionMapping mapping, ActionForm actionForm,            HttpServletRequest request, HttpServletResponse response)            throws Exception {        if( this.verifyRoot(request) )            return mapping.findForward(Const.ACCESS_DENY);        try{            loadForm(request);            cs.delete(id);            request.setAttribute("courses",cs.getByYear(null));        }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);        }        request.setAttribute(Const.MESSAGES,"删除成功");        return mapping.findForward(Const.VIEW);    }                //修改课程    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);            Course c = new Course(name,credit,year,term,teacherId);            c.setHour(hour);            c.setExamMode(examMode);            c.setExamType(examType);            c.setType(type);            c.setId(id);            cs.updateOrCreate(c);        }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("course",cs.get(id));            }catch(StoreException se){                request.setAttribute(Const.MESSAGES,"数据库出错");                return mapping.findForward(Const.STORE_EXCEPTION);            }        }        request.setAttribute(Const.MESSAGES,"修改成功");        return mapping.findForward(Const.UPDATE);    }            //获取课程    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("course",cs.get(id));        }catch(StoreException se){            request.setAttribute(Const.MESSAGES,"数据库出错");            return mapping.findForward(Const.STORE_EXCEPTION);        }        return mapping.findForward(Const.UPDATE);    }                //view    public ActionForward view(ActionMapping mapping, ActionForm actionForm,            HttpServletRequest request, HttpServletResponse response)            throws Exception {        if( this.verifyRoot(request) )            return mapping.findForward(Const.ACCESS_DENY);        try{            loadForm(request);            java.util.List list = null;            if( year!=null && term!=null && term.length()>0 )                list = cs.getByYearAndTerm(year,term);            else if( year!=null )                list = cs.getByYear(year);            else{                list = cs.getByYear(null);            }            request.setAttribute("courses",list);        }catch(StoreException se){            request.setAttribute(Const.MESSAGES,"数据库出错");            return mapping.findForward(Const.STORE_EXCEPTION);        }        return mapping.findForward(Const.VIEW);    }    }

⌨️ 快捷键说明

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