package com.hrs.controller.user;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**   
* Copyright: Copyright (c) 2026 chinasofti
* 
* @ClassName: LogoutController.java
* @Description: 退出登录控制器
*
* @version: v1.0.0
* @author: 李鑫
* @date: 2026年4月13日 上午9:06:00 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* 2026年4月13日     李鑫           v1.0.0               新建文件
*/
@WebServlet("/user/logout")
public class LogoutController extends HttpServlet {
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        
        // 1. 获取Session
        HttpSession session = request.getSession(false);
        
        // 2. 如果Session存在，销毁它
        if (session != null) {
            session.invalidate();
        }
        
        // 3. 跳转到登录页面
        response.sendRedirect(request.getContextPath() + "/user/login");
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        doGet(request, response);
    }
}