| Author |
Servlet Context parameters
|
ragi singh
Ranch Hand
Joined: Mar 10, 2010
Posts: 198
|
|
Hi ,
I am reading Head First Servlet and JSP . and in one of the examples they have used the context parameter in the web.xml , my question is if the context parameters are for the entire application then they should be declared in some tag at application scope and not web.xml .
If i have a simple web-app and i want to add the context parameters where should i declare it (in the web.xml of a servlet , also if we declare the context parameters in the web.xml of a particular servlet what if this servlet is not loaded at all then how will we ever b able to read the context parameters)
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 629
|
|
context parameters are for the entire application therefore it is declared in <web-app> ...</web-app> and not inside <servlet> ... </servlet>.
|
Life is easy because we write the source code.....
|
 |
ragi singh
Ranch Hand
Joined: Mar 10, 2010
Posts: 198
|
|
|
no i mean to say the context patameters must be defined in some globally accessible xml in the web-app instead of the web.xml in the servlet
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 629
|
|
|
web.xml is globally accessible xml file. At the start up of your web application web.xml is read first.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
ragi singh wrote:my question is if the context parameters are for the entire application then they should be declared in some tag at application scope and not web.xml .
web.xml is the perfect place to declare them.
also if we declare the context parameters in the web.xml of a particular servlet
web.xml declares all servlets. And there is only one web.xml per application.
what if this servlet is not loaded at all then how will we ever b able to read the context parameters)
The context params have nothing at all to do with whether a servlet is loaded or not. Nothing at all. Any context params declared in the web.xml will always be available.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
ragi singh
Ranch Hand
Joined: Mar 10, 2010
Posts: 198
|
|
|
Yeah thank you , i got the point .
|
 |
 |
|
|
subject: Servlet Context parameters
|
|
|