본문 바로가기

IT/java

javax.servlet.ServletException: Cannot expose session attribute 'id' because of an existing model object of the same name javax.servlet.ServletException: Cannot expose session attribute 'id' because of an existing model object of the same name

심각: Servlet.service() for servlet dispatcher threw exception

javax.servlet.ServletException: Cannot expose session attribute 'id' because of an existing model object of the same name 


계속 세션을 유지하면서. 세션에서 사용자의 id와 권한을 유지하려고 했는데 위와같은 에러가 발생하였다.

이유는 ModelAndView에 세팅해 준 값들도 결국엔 내부적으로

mav.addObject("id", id);
request.getSession().setAttribute("id", id) 
 
이렇게 session에 Attribute로 지정되기 때문이다.

request.getSession().setAttribute("uid", id);
이렇게 uid로 이름을 변경하여 지정해 준 이후 문제는 해결되었다.

자문 : 강경보선생