Declare Servlet 3.0 Initialization parameter using @WebInitParam

Servlet initialization parameters are used to process the data when servlet initializing. Before servlet 3, this data need to put on deployment descriptor and servlet will read the data in init() method using ServletConfig Object. For every servlet, the data is unique and not been shared in between of two servlets.

Before Servlet 3 Initialization parameter declared in web.xml as following

Servlet 3 come with @WebInitParam annotation, using which developer can define the initialization parameter in Servlet itself. Later servlet can access that parameter by using config.getInitParameter() method.

Following example demonstrate the use of @WebInitParam annotation in Servlet 3.

The output will look like similar to following…

Servlet3 WebInitParam Example

About the Author

has written 69 posts.

I Love Coding, Analyzing, Designing and doing it the right way. I am obsessed about learn anything new daily and sharing what I have learn each Day. This Blog is journey of my Zeal, going through step by step to the mountain of desire to become prefect. Google Wanna Hire me ?

Copyright © 2020 All rights reserved.
Proudly powered by WordPress. Developed by 7Tech Solutions