一个简单的超市订单管理系统(4)-用户注销和权限拦截

一个简单的超市订单管理系统(4)-用户注销和权限拦截

1.注销功能:移除session,返回登录页面即可

  (1)编写移除注销功能的servlet

 1 package com.xiaoma.servlet.user;
 2 
 3 import com.xiaoma.util.Constants;
 4 
 5 import javax.servlet.ServletException;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 import java.io.IOException;
10 
11 public class LogoutServlet extends HttpServlet {
12     @Override
13     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
14         //移除session
15         req.getSession().removeAttribute(Constants.USER_SESSION);
16         //重定向到登录页面
17         resp.sendRedirect(req.getContextPath()+"/login.jsp");
18     }
19 
20     @Override
21     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
22         doGet(req, resp);
23     }
24 }
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » 一个简单的超市订单管理系统(4)-用户注销和权限拦截