Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Context parameters

 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
context parameters are for the entire application therefore it is declared in <web-app> ...</web-app> and not inside <servlet> ... </servlet>.

 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah thank you , i got the point .
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic