[FIX] エラー画面でセッション廃棄されない問題を修正しました。
This commit is contained in:
@@ -4,6 +4,8 @@ package com.example.demo.aop.handler;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
@@ -37,25 +39,31 @@ public class GlobalExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
@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("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||||
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
|
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||||
|
|
||||||
|
System.out.println("session invalidated");
|
||||||
|
session.invalidate();
|
||||||
|
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@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);
|
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||||
|
|
||||||
|
System.out.println("session invalidated");
|
||||||
|
session.invalidate();
|
||||||
|
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user