📄 specialactions.java
字号:
/*
* SpecialActions.java
*
* Created on 2006年5月31日, 上午12:06
*
* 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 SpecialActions extends DispatchAction {
private String name;
private Integer id;
private Integer departmentId;
private SpecialService ss = (SpecialService)ServiceFactory.makeService("SpecialService");
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;
}
try{
int intDepartmentId = Integer.parseInt(request.getParameter("departmentId"));
this.departmentId = new Integer(intDepartmentId);
}catch(Exception e){
this.departmentId = 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);
Special s = new Special(name,departmentId);
ss.updateOrCreate(s);
}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{
loadForm(request);
request.setAttribute("departments",ds.getAll());
request.setAttribute("specials",ss.getByDepartmentId(departmentId));
}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);
ss.delete(id);
request.setAttribute("departments",ds.getAll());
}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("specials",ss.getByDepartmentId(departmentId));
}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("special",ss.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);
Special s = new Special(name,departmentId);
s.setId(id);
ss.updateOrCreate(s);
}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("special",ss.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 + -