Servlet 3 Initialization Parameter Annotation @WebInitParam

This tutorial shows you how use the servlet 3 initialization parameter annotation @WebInitParam to inject initialized parameters in a servlet. We can configure a servlet entirely with annotations and without using web.xml configuration. This is third post of series of <a href=”http://javabycode.com/java-frameworks/servlet-jsp/java-servlet-tutorial-java-servlet-example.html” target=”_blank”>Java Servlet Tutorial</a>. This series tutorial will provide you full knowledge about Servlet 3.0.

Project structure

Servlet 3 Initialization Parameter Annotation
Servlet 3 Parameter Annotation Example

Maven Dependency

Servlet 3 initialization parameter annotation
The @WebInitParam annotation is used to initialize parameters for a servlet or filter. The servlet 3 parameter takes a required name and value. You can add a description for a servlet or filter also. You can get initialized parameters using the servletConfig.getInitParameter() method in the init() method.

Deploy Servlet 3 Initialization Parameter Annotation on application server
This example is deployed on tomcat 8 with the below address.
URL: http://localhost:8080/servlet-param/example

Here is output

Servlet 3 Initialization Parameter Annotation
Servlet 3 Initialization Parameter Annotation deploy

That’s all. Now you can customize this example and implement your own Servlet 3 Parameter Annotation Example. You can also find other servlet example in the series of <a href=”http://javabycode.com/java-frameworks/servlet-jsp/java-servlet-tutorial-java-servlet-example.html” target=”_blank”>Java Servlet Example</a>.

In the next tutorial, we will show you how to create Servlet 3 Initialization Parameter example using web.xml configuration.

Download complete source code, please click link below

Servlet-3-Parameter-Annotation-Example.zip (45 downloads)


Leave a Comment

*

Please share it if you found this useful
Hide Buttons