import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

public abstract class BaseAction extends Action {
    public ActionForward execute(
            ActionMapping mapping, 
            ActionForm form,
            HttpServletRequest request, 
            HttpServletResponse response)
            throws IOException, ServletException {
        response.setHeader("Cache-Control", "no-cache");
        //    强迫页面从服务端获取数据
        response.setHeader("Cache-Control", "no-store");
        //在任何情况下都不缓存页面
        if (!this.userIsLoggedIn(request)) {
            ActionErrors errors = new ActionErrors();
            errors.add("error", new ActionError("logon.sessionEnded"));
            this.saveErrors(request, errors);
            return mapping.findForward("fail");
        }
        return executeAction(mapping, form, request, response);
    }

    protected abstract ActionForward executeAction(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws IOException, ServletException;

    private boolean userIsLoggedIn(HttpServletRequest request) {
        if(request.getSession().getAttribute("User") == null)
            return false;
    	return true;
    }
}
