配置过滤器时,我可以将一些值作为web.xml中的初始参数传递给过滤器,并通过FilterConfig在Filter中获取这些值。 如何在web.xml中为HttpSessionListener配置一些初始参数?如果这是不可能的,还有什么替代方案?
答案 0 :(得分:8)
在代码中:
public class MyListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
String value = event.getSession().getServletContext().getInitParameter(paramName);
}
}
在web.xml中:
<web-app ...>
...
<context-param>
<param-name>my_param</param-name>
<param-value>12345</param-value>
</context-param>