jsp页面中用户注销的写法

jsp页面

 

1 <c:if test="${not empty sessionScope.user}">
2         <div class="logout right"><a href="doLogoutServlet" title="注销">注销</a></div>
3     </c:if>

 

 

doLogoutServlet

 

 

 1 public void doPost(HttpServletRequest request, HttpServletResponse response)
 2             throws ServletException, IOException {
 3         try {
 4             if(request.getSession().getAttribute("user")==null)
 5                 throw new Exception("登录已超时!");
 6             Boolean isAdmin = ((Auctionuser)request.getSession().getAttribute("user")).getUserisadmin();
 7             request.getSession().invalidate();
 8             if(isAdmin){
 9                 response.sendRedirect("login-admin.jsp");
10             }else{
11                 response.sendRedirect("login.jsp");
12             }            
13         } catch (Exception e) {
14             // TODO Auto-generated catch block
15             e.printStackTrace();
16             request.setAttribute("message", e.getMessage());
17             request.getRequestDispatcher("error.jsp").forward(request,response);
18         }
19     }

 

 

 

 

invalidate无效的,使作废,用于注销用户信息

转载于:https://www.cnblogs.com/jimorulang/p/5557925.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值