From the course: Java EE: Servlets and JavaServer Pages (JSP)
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Using ServletContext
From the course: Java EE: Servlets and JavaServer Pages (JSP)
Using ServletContext
- [Instructor] Now let us take a look at the ServletContext API, as opposed to ServletConfig, the ServletContext API will be used to pass configuration information for the entire application, as in, if you want to share any information across all the Servlets of your application then you need to grab the ServletContext object. Now for the ServletContext object as well, there will be parameters defined and they will be defined in the deployment descriptor which is our webXML file. Now please note that since it is for the entire application these parameters wouldn't be attached to a particular Servlet but they'd be attached to the entire app. The parameters like your Servlet configure again in the form of key-value pair and always of the type String. There's always one ServletContext object for the entire application, this is not going to be for every Servlet basis but it's going to be as an application basis. So lets try this out in the demo, we go to our getServlet, let me get rid of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.