Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass init parameters to HttpSessionListener?

Tags:

java

servlets

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?

like image 531
Dan Avatar asked May 22 '10 18:05

Dan


1 Answers

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>
like image 124
skaffman Avatar answered Oct 22 '22 17:10

skaffman