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

📄 teacheractions.java

📁 are are are are are are are are are are are are
💻 JAVA
字号:
/* * TeacherActions.java * * Created on 2006年6月3日, 下午7:42 * * 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 TeacherActions extends DispatchAction {        private Integer id;    private String username;    private String password;    private String name;    private String sex;    private TeacherService ts = (TeacherService)ServiceFactory.makeService("TeacherService");        private void loadForm(javax.servlet.http.HttpServletRequest request){        this.username = request.getParameter("username");        this.password = request.getParameter("password");        this.name = request.getParameter("name");        this.sex = request.getParameter("sex");        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);            Teacher t = new Teacher(username,password,name);            t.setSex(sex);            ts.updateOrCreate(t);        }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);    }        //根据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);            ts.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("teachers",ts.getByUsername(null));            }catch(StoreException se){                request.setAttribute(Const.MESSAGES,"数据库出错");                return mapping.findForward(Const.STORE_EXCEPTION);            }        }        return mapping.findForward(Const.VIEW);    }            //获取教师 for 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( (username!=null&&username.length()>0) && (name!=null&&name.length()>0))                list = ts.getByNameAndUsername(name,username);            else if(username!=null && username.length()>0)                list = ts.getByUsername(username);            else                list = ts.getByName(name);            request.setAttribute("teachers",list);        }catch(StoreException se){            request.setAttribute(Const.MESSAGES,"数据库出错");            return mapping.findForward(Const.STORE_EXCEPTION);        }        return mapping.findForward(Const.VIEW);    }            //获取教师 for 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("teacher",ts.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);            Teacher t = new Teacher(username,password,name);            t.setSex(sex);            t.setId(id);            ts.updateOrCreate(t);        }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);        }finally{            try{                request.setAttribute("teacher",ts.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 + -