This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Context parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Context parameters" Watch "Servlet Context parameters" New topic
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: 60806
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

Yeah thank you , i got the point .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Context parameters
 
Similar Threads
Can we dynamically load servlet?
init parameters
servletcontext-attribute
parameter and attribute in servlet
where are the request parameters declare