From the course: Jakarta EE Servlets

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Configuration with context parameters

Configuration with context parameters - Jakarta EE Tutorial

From the course: Jakarta EE Servlets

Configuration with context parameters

- [Instructor] When our servlet application needs to declare a configuration parameter that can be accessed by every servlet, we need to use a context parameter. To demonstrate this, let's imagine that our product service needs to be instantiated using a static factory method that accepts a connection string. We can declare that connection string as a context parameter within our web dot XML file. So here at the bottom of the file, I'm going to use the context-peram tag and then within it, I'm going to add a peram-name tag. This will allow us to specify the name of the new context parameter that we'd like to create. I'm going to call it connection string. Now, we can add another tag within our context peram tag that will allow us to set the value for this context parameter. That tag is the peram-value tag. And here I'm just going to create a connection string. We'll say we're using the SQL protocol, and then we'll…

Contents