JSP/JSP: 프로그래밍 코드

[JSP:프로그래밍 코드] 세션의 모든 데이터를 출력하는 프로그래밍 코드

데브마우스 2024. 2. 23. 09:06

세션에 이것저것 담아놓고 테스트를 할 때가 있습니다.

 

이럴 때 유용한 코드입니다.

 

getAttributeNames() 메서드로 세션의 모든 Key 값을 가져옵니다.

그리고 Key 값을 기반으로 모든 Value 값을 출력시키는 프로그래밍 코드입니다.

Enumeration<String> attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
    String attributeName = attributeNames.nextElement();
    Object attributeValue = session.getAttribute(attributeName);
    System.out.println(attributeName + " : " + attributeValue);
}