简体   繁体   中英

How can I pass init parameters to HttpSessionListener?

When configuring filters, I can pass some values to a filter as initial parameters in web.xml and obtain those values in Filter via FilterConfig. How can I configure some initial parameters in web.xml for HttpSessionListener? If this is not possible, what are alternatives?

In the code:

public class MyListener implements HttpSessionListener {

   public void sessionCreated(HttpSessionEvent event) {
      String value = event.getSession().getServletContext().getInitParameter(paramName);
   }
}

And in web.xml:

<web-app ...>
...
    <context-param>
        <param-name>my_param</param-name>
        <param-value>12345</param-value>
    </context-param>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM