新建一个BaseAction:
testAction中
public abstract class BaseAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
ActionForward forward = null;
forward = run(mapping, form, request, response);
Cookie ck[]=request.getCookies();
String login=null;
for(int i=0;i<ck.length;i++){
if(ck[i].getName().equals("cookielogin"))
login=ck[i].getValue();
}
if(request.getSession().getAttribute("login")==null&&StringUtils.isEmpty(login))
return mapping.findForward("login");
return forward;
}
public abstract ActionForward run (ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws SQLException, Exception;
}
testAction中
public ActionForward run(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws SQLException, Exception {
ActionForward forward = null;
if (mapping.getPath().equals("/test")) {
forward = testaction(mapping, form, request, response);
}
return forward;
}
public ActionForward testaction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
.....