📄 classactions.java
字号:
/*
* ClassActions.java
*
* Created on 2006年6月5日, 上午1:51
*
* 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 ClassActions extends DispatchAction {
private Integer id;
private Integer teacherId;
private Integer specialId;
private Integer enrollYear;
private String name;
private ClassService cs = (ClassService)ServiceFactory.makeService("ClassService");
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;
}
try{
int intTeacherId = Integer.parseInt(request.getParameter("teacherId"));
this.teacherId = new Integer(intTeacherId);
}catch(Exception e){
this.teacherId = null;
}
try{
int intSpecialId = Integer.parseInt(request.getParameter("specialId"));
this.specialId = new Integer(intSpecialId);
}catch(Exception e){
this.specialId = null;
}
try{
int intEnrollYear = Integer.parseInt(request.getParameter("enrollYear"));
this.enrollYear = new Integer(intEnrollYear);
}catch(Exception e){
this.enrollYear = 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);
enova.pojo.Class c = new enova.pojo.Class(name,specialId,enrollYear);
c.setTeacher( new Teacher(teacherId) );
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);
}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("classes",cs.getBySpecialId(specialId));
}catch(StoreException se){
request.setAttribute(Const.MESSAGES,"数据库出错");
return mapping.findForward(Const.STORE_EXCEPTION);
}
}
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);
enova.pojo.Class c = new enova.pojo.Class(name,specialId,enrollYear);
c.setTeacher(new Teacher(teacherId));
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("class",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);
}
//根据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("class",cs.get(id));
}catch(StoreException se){
request.setAttribute(Const.MESSAGES,"数据库出错");
return mapping.findForward(Const.STORE_EXCEPTION);
}
return mapping.findForward(Const.UPDATE);
}
//查看班级
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( specialId!=null && enrollYear!=null )
list = cs.getBySpecialIdAndEnrollYear(specialId,enrollYear);
else if( specialId!=null && enrollYear==null )
list = cs.getBySpecialId(specialId);
else if( specialId==null ){
request.setAttribute(Const.MESSAGES,"请选择先一个专业");
list = cs.getBySpecialId(null);
}
request.setAttribute("classes",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 + -