【发布时间】:2012-02-29 14:43:24
【问题描述】:
在ServletContextListener 中,我设置了这样的属性:
ArrayList<String> prefs = new ArrayList<String>();
...
...
sc.setAttribute("user-preferences", prefs);
我尝试在这样的 JSP 页面中使用该属性:
ArrayList<String> prefs = (ArrayList<String>) config.getServletContext().getAttribute("user-preferences");
我收到以下警告:
类型安全:从 Object 到 ArrayList 的未经检查的强制转换
谁能告诉我为什么会收到这个警告?
谢谢。
【问题讨论】:
-
我在你的源代码中有一个问题,你为什么不使用 application.getAttribute() 从 servletContext 中获取属性?
-
@Naved:是的,谢谢。我应该这样做的。
-
你为什么不用EL?由
${prefs}等提供。