/*
* 项目名 :北京五岳管理系统
* 副系统名 :继承自stucts的Action抽象类
* class名 :AdmitAction.java
* version :1.0
* 日期 :2005/07/06
* 著作权 :Copyright beijingwuyue 2005, All rights reserved.
*/
package admit.action;
import admit.form.AdmitForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;
/**
* <p>Title: AdmitAction.java</p>
* <p>Description: 继承自stucts的Action抽象类</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: 五岳</p>
*
* @author gongjian
* @version 1.0
*/
public abstract class AdmitAction extends Action {
//定义Log日志对象,在子类中可以直接使用
protected Log log = LogFactory.getLog(this.getClass());
//定义一个Request对象
private HttpServletRequest requestHandler;
/*
* 重写structs包的方法,用final关键字修饰之后无法在子类被重写
*
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMappinaaorg.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public final ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
requestHandler=request;
log.debug("-= execute start=-");
//forward
ActionForward forward = null;
try {
//从ActionForm中提取数据
AdmitForm admitForm = (AdmitForm) form;
AdmitActionContext context = new AdmitActionContext(request);
String result = "";
//登陆
if (CheckLogin(context)) {
result = this.execute(admitForm, context);
}
//没有登陆
else {
result = "error";
}
//根据result在structs-config.xml文件中寻找相对应的路径和文件
forward = mapping.findForward(result);
} catch (Exception e) {
log.error(e);
forward = mapping.findForward("error");
}
log.debug("-= execute end =-");
return forward;
}
/**
* 抽象类,子类使用,返回确定转向的字符串
*
* @param Form ActionForm
* @param context ActionContext
* @return String 用于转向的字符串
* @throws Exception
*/
public abstract String execute(AdmitForm form, AdmitActionContext context)
throws Exception;
/**
* 检查用户是否登陆
*
* @param context ActionContext
* @return true 用户已经登陆
* false 用户没有登陆
*/
public boolean CheckLogin(AdmitActionContext context) {
String login = (String)context.getSessionData("login");
if ("1".equals(login)) {
return true;
} else {
return false;
}
}
/**
*
* @return
*/
public MessageResources getMessageResources(){
return getResources(requestHandler);
}
}