[Java]getAttributeでHttpリクエスト属性を取得する
関数
1.Enumeration <String> getAttributeNames()
このリクエストで使用可能な属性の名前を含む Enumeration を返します。リ
2.getAttribute(String name)
指定された名前の属性が存在しない場合、名前付き属性の値を Object、または null として返します。
使用例
StringBuilder sb = new StringBuilder();
// 全リクエスト属性名を取得
Enumeratio<?> objNames = request.getAttributeNames();
while (objNames.hasMoreElements()) {
// 属性名を取得
String strAtt = (String)objNames.nextElement();
// 値を取得
Object resValue = request.getAttribute(strAtt);
sb.append(strAtt);
sb.append(":");
sb.append(resValue);
sb.append("\n");
}
System.out.print(sb.toString());