是否登录,是否过期
在一个web项目中,判断用户是否登录或者 session是否过期 是非常重要的
在struts中的实现
做个BaseAction继承DispatchAction,然后所有ACTION继承此BaseAction
BaseAction主要代码片段
/**
* override method.
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{ //用户如果未登录或session过期,则转向登录动作。
if (!isLogin(request))
return mapping.findForward("sessionEnd");
try
{
// ActionForward forward = new ActionForward();
//重新生成token
//super.saveToken(request);
return super.execute(mapping, form, request, response);
} catch (Exception e)
{
// logger.error(e);
e.printStackTrace();
return mapping.findForward("systemError");
}
}
以后所有类继承此基类
LinkAction extends ActionX
由于DispatchAction特点,所有继承BaseAction的类都可以正常写单独方法完成。
还有一种方式当然是 过滤器了