About Question enthuware.jwpv6.2.603 :
Posted: Sun Oct 16, 2011 9:22 am
None of the answers is correct.
Despite the fact that API description says that @WebInitParam annotation can be used on Servlet and Filter classes to define init parameter this is not correct.
Servlet 3.0 Specification
I have made some test on Tomcat 7.0.22 and Glassfish 3.1.1 and if you use @WebInitParam outside @WebServlet annotation it is just ignored.
Despite the fact that API description says that @WebInitParam annotation can be used on Servlet and Filter classes to define init parameter this is not correct.
Servlet 3.0 Specification
@WebInitParam can be used only as parameter to @WebServlet and @WebFilter annotations:8.1.3 @WebInitParam
This annotation is used to specify any init parameters that must be passed to the
Servlet or the Filter. It is an attribute of the WebServlet and WebFilter
annotation.
Code: Select all
@WebServlet(urlPatterns="/AuthenticationServlet", initParams=@WebInitParam(name="test", value="testVal"))
public class AuthenticationServlet extends HttpServlet {}