【发布时间】:2018-09-05 01:44:33
【问题描述】:
我有一个可能属于此类的请求对象:https://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/connector/RequestFacade.html
我正在尝试打印属性的名称及其值。这是我徒劳的尝试。
Enumeration rns = request.getAttributeNames();
while (rns.hasMoreElements()) {
Object param = rns.nextElement();
out.println("\nattribute name: " + param.toString());
out.println("attribute value: " + request.getAttribute(param.toString()));
}
我错过了什么?在另一种语言中,这样的问题有一个简单的答案。它在java中完成有什么不同? Rails: How do I print the request parameters?
我的硬编码尝试
Enumeration rns = request.getAttributeNames();
while (rns.hasMoreElements()) {
out.println("\nattribute name: " + rns.nextElement() );
}
// i have copied the logs output from above and edited it to create the array below
String[] madAttrs = { "dayToGraph",
"yearFromGraph",
"yaxis",
"yearToGraph",
"monthToGraph",
"monthFromGraph",
"currentMachine",
"onlyGraph",
"currentSample",
"currentAnalyte",
"dayFromGraph",
"analyteid"};
// then I got what I want.
for (String an : madAttrs) {
out.println("sttribute " + an);
out.println("the value is: "+ request.getAttribute(an));
}
但是如果不对数组中的属性进行硬编码,我该怎么做呢?
【问题讨论】:
-
你的问题是?究竟什么不起作用?它是一个 servlet 吗?
-
你搜索
Session属性吗? -
什么不起作用?你有例外吗?出现了什么?你想要什么?
-
@ruby_object 请发布您的 JSP 而不仅仅是上面的 sn-p。
标签: java