[FIX] エラー画面でセッション廃棄されない問題を修正しました。

This commit is contained in:
s-choi
2026-09-28 15:51:16 +09:00
parent d7a0aac355
commit efdaacbb27

View File

@@ -4,6 +4,8 @@ package com.example.demo.aop.handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.servlet.http.HttpSession;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.HttpRequestMethodNotSupportedException;
@@ -37,7 +39,7 @@ public class GlobalExceptionHandler {
}
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public String handleBadRequestException(Model model, Exception e) {
public String handleBadRequestException(Model model, Exception e, HttpSession session) {
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
@@ -45,17 +47,23 @@ public class GlobalExceptionHandler {
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
System.out.println("session invalidated");
session.invalidate();
return "error";
}
@ExceptionHandler(Exception.class)
public String AllException(Model model, Exception e) {
public String AllException(Model model, Exception e, HttpSession session) {
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
System.out.println("session invalidated");
session.invalidate();
return "error";
}
}