From the course: Java EE: Servlets and JavaServer Pages (JSP)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using ServletConfig
From the course: Java EE: Servlets and JavaServer Pages (JSP)
Using ServletConfig
- Now let us understand a few other important APIs which are critical under the Servlet specification. The first one among them is the ServletConfig API. This is the one which is used to pass any kind of configuration information to a particular servlet. For example, let's say you're servlet wants to register to a web service URL. Or let's say it wants to register itself to a weather service URL. In that case, when you write out the code the URL will be hard-coded into the servlet class. But there's no need to hard-code because it's not a good practice. What we could do is, we could imbed this URL information in the form of config init parameter. These init parameters are typically defined in the deployment descriptor, which is our webxml file. And they're always defined under servlet element. These parameters that we define are of course in the form of a key and a value pair. And they're always of the string type. Once these parameters are defined in the deployment descriptor, they…
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.