如何很好地实现注销功能呢?~

yongzonglai 2010-05-19 06:45:58

我是用session做的登陆页面~
我用清除session的方法来实现注销
可是在注销之后 我点后退按钮 然后再刷新 注销的用户又自动登陆了 ~~
...全文
273 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinchun1234 2010-05-21
  • 打赏
  • 举报
回复
right
lvchao7758520 2010-05-21
  • 打赏
  • 举报
回复
解决了就好..只要能解决问题的方法就是好方法
yongzonglai 2010-05-21
  • 打赏
  • 举报
回复
我知道该怎么做了 我也可以让浏览器的后退按钮不能用

第一步添加登录过滤器:

public class OnlineFilter extends HttpServlet implements Filter
{
private static final long serialVersionUID = 1L;
public void init(FilterConfig filterConfig) throws ServletException
{

}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
RequestDispatcher dispatcher = request.getRequestDispatcher("KK_BlacklistVehicle_UserLogin.jsp");//这里设置如果没有登陆将要转发到的页面
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
HttpSession session = req.getSession(true);

// System.out.println(((HttpServletRequest) request).getRequestURI());
// 从session里取的用户名信息
String username = (String) session.getAttribute("sessionKK_BlacklistVehicle_UserLogin_ID");//这里获取session,为了检查session里有没有保存用户信息,没有的话回转发到登陆页面

// 判断如果没有取到用户信息,就跳转到登陆页面
if (username == null || "".equals(username))
{
// 跳转到登陆页面
dispatcher.forward(request,response);
// System.out.println("用户没有登陆,不允许操作");

res.setHeader("Cache-Control","no-store");
res.setDateHeader("Expires",0);
res.setHeader("Pragma","no-cache");
}
else
{
// 已经登陆,继续此次请求
chain.doFilter(request,response);
// System.out.println("用户已经登陆,允许操作");
}
}
public void destroy()
{

}
}


第二步注销:
/**
* 登出
*/
public ActionForward logout(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
/** 清除session中的用户信息并销毁当前session */
request.getSession().removeAttribute("user");
request.getSession().invalidate();
response.sendRedirect("/SIMS/index.jsp");
return null;
}
xinleicn 2010-05-21
  • 打赏
  • 举报
回复
空心兜兜 2010-05-20
  • 打赏
  • 举报
回复
………………怎么会这么怪
SDMRauquin 2010-05-20
  • 打赏
  • 举报
回复
登陆后的那些页面或者action,是否有判断session不存在而返回首页的?
Mars_Ma_OK 2010-05-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 haoren_e 的回复:]
正确的登出系统:

Java code

/**
* 登出
*/
public ActionForward logout(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
……
[/Quote]

1.登录的时候你肯定是要拿到session id,然后还有用户等等.如果你session销毁了,再次刷新的时候session应该不会相同了吧..session id应该也不会相同了.所以你要判断session id是否相等..
lvchao7758520 2010-05-20
  • 打赏
  • 举报
回复
//用户登陆 对象放入session
session.setAttribute("userid",user);
//注销
session.removeAttribute("userid");
//登陆的时候判断session的userid 是不是为空就行了
飞哥在线 2010-05-19
  • 打赏
  • 举报
回复
在你的登陆页面做处理
比如你的页面验证是否登陆信息为userid,则在你的登陆页面里面加入如下代码
session.setAttribute("userid",null);

haoren_e 2010-05-19
  • 打赏
  • 举报
回复
正确的登出系统:

/**
* 登出
*/
public ActionForward logout(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
/** 清除session中的用户信息并销毁当前session */
request.getSession().removeAttribute("user");
request.getSession().removeAttribute("modules");
request.getSession().removeAttribute("functions");
request.getSession().removeAttribute("allUsers");
request.getSession().invalidate();
response.sendRedirect("/SIMS/index.jsp");
return null;
}

这个后退是通过 浏览器 回到上一个页面,你那样操作当然能回到之前的页面,我想你控制不了这个吧,但是你的session里的user确实已经没有了,你可以测试一下,从session中获取一下user的信息看看。
stl0 2010-05-19
  • 打赏
  • 举报
回复
首先检查当前session是否为空,然后检查session时候和登录时的session一致

btw:登录后的session值(比如sessionId)的保存你是怎么做的? 普通做法是登录后把sessionId保存到DB,或者服务器的Memcached中。当然也有其他保存方法。
yongzonglai 2010-05-19
  • 打赏
  • 举报
回复
session确实destroy了
第二步要对session检查什么东西啊,怎么检查?
cooljia 2010-05-19
  • 打赏
  • 举报
回复
需要注销session,另外需要检查cookie信息。
stl0 2010-05-19
  • 打赏
  • 举报
回复
首先确认2点
1.session确实destroy了么?
2.后退刷新的时候,对session进行检查了么?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧