最近在做自己的一个小项目,退出的时候遇到困难了,请大家看一下,下面有详细代码,不对请指出
挺急的,谢谢大家!
(1).这是页面的链接
(2).这是struts配置文件中的action
class="com.ldr.bysj.web.action.AdminMgrAction">
/login.jsp
(3).下面是action中的方法
public String stulogout() {
ActionContext ctx = ActionContext.getContext();
ctx.getSession().remove("student");
return SUCCESS;
}
已经获取用户信息并共享在session中!
这样,退出的时候虽然退出了,但后退还是能回到上一级页面
[code="java"]
class CheckLogin implements Filter{
doFilter(ServletRequest request, ServletResponse response,
FilterChain chain){}
HttpServletRequest httpRequest=(HttpServletRequest)request;
String personId=(String) httpRequest.getSession().getAttribute(Constants.SESSION_CURRENT_PERSONID);
if(personId==null||personId.equals(""))
((HttpServletResponse)response).sendRedirect(httpRequest.getContextPath() + "/LoginAction!input.do");
else
chain.doFilter(request, response);
}
[/code]
xml里面也要配置filter过滤的内容,注意过滤的顺序
如果使用mvc
Interceptor控制action也可以
可以加个Filter过滤。可以判断当前用户有没有登录。没有登录让它跳转到登录页面。
呵呵,楼上正解!