当前页面: 开发资料首页 → JSP 专题 → 关于Application对象的一个奇怪问题
关于Application对象的一个奇怪问题
摘要: 关于Application对象的一个奇怪问题
我编写了一个JSP程序:
<%@ page contentType="text/html; charset=gb2312" %>
<%!
class User
{
String userName;
String email;
User(String userName,String email)
{
this.userName=userName;
this.email=email;
}
...
}
%>
<body>
<%
String userName=request.getParameter("userName");
String email=request.getParameter("email");
User user=new User(userName,email);
application.setAttribute(userName,user);/*userName中存放的字符串作为属性名,user对象作
为属性值*/
Enumeration e=application.getAttributeNames();
while(e.hasMoreElements())
{
String name = (String)e.nextElement();
out.print(name);
}
%>
</body>
在页面上输出的name为org.apache.catalina.jsp_classpathjavax.servlet.context.tempdirabdcabcorg.apache.catalina.resourcesabdcdorg.apache.catalina.WELCOME_FILES
我觉得非常奇怪,我明明以userName中包含的字符串作为属性名称,为什么会输出成这样呢?
有没有哪位大虾回答一下我的问题啊
Enumeration e=application.getAttributeNames();
getAttributeNames()得到的是属性名而不是值