tags:

views:

190

answers:

1

Thanks to everyone in advance,

I am trying to access any context parameters in the web.xml from within a servlet filter. Below is a portion from my web.xml file. I have verified that the context-param node is accessible via a jsp page using out.print(getServletContext().getInitParameter("error"));.

  <filter>
<filter-name>prePost</filter-name>
<filter-class>MyFilter</filter-class>
<init_param>
  <param_name>error</param_name>
  <param_value>/test.jsp</param_value>
</init_param>

  <filter-mapping>
<filter-name>prePost</filter-name>
<url-pattern>*.jsp</url-pattern>

  <context-param>
<description>Error Handler</description>
<param-name>error</param-name>
<param-value>/test.jsp</param-value>

In my filters doFilter when I output this.filterConfig.getInitParameter("error"), I always get null. In my filters init() I am setting this.filterConfig with the passed in FilterConfig.

Thanks,

Sam

+3  A: 

You're using underscores rather than hyphens for "param-name" and "param-value". Your config should look like this:

<init-param>
    <param-name>error</param-name>
    <param-value>/test.jsp</param-value>
</init-param>
kdgregory