Initializing your JSP
You can do servlet initialization stuff in your JSP, but it’s slightly different from what you do in a regular servlet.
Configuring servlet init parameters
You configure servlet init params for your JSP virtually the same way you configure them for a normal servlet. The only difference is that you have to add a <jsp-file> element within the <servlet> tag.

Overriding jspInit()
Yes, it’s that simple. If you implement a jspInit() method, the Container calls this method at the beginning of this page’s life as a servlet. It’s called from the servlet’s init() method, so by the time this method runs there is a ServletConfig and ServletContext available to the servlet. That means you can call getServletConfig() and getServletContext() from within the jspInit() method.
This example uses the jspInit() method to retrieve a servlet init parameter (configured in the DD), and uses the value to set an application-scoped attribute.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access