Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Init-Params and COntext-Params

 
A Dev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey..

When do we use Init-params nad not context-params. please explain this with example.

I know the difference between them, but when there are Context-params, why do we need init-params??? using Context-params are always better than init-params as Entire Appln. can use it.
 
damodar kumar
Ranch Hand
Posts: 77
Android Chrome MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
context param is for entire session of client so if you keep unnecessary things there it will become overhead for application
inti param is for that particular request or response

you need to differentiate where and when we can use those.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
damodar kumar wrote:inti param is for that particular request or response

That is not correct. Init params apply to a particular servlet, not a single request.

Context params should be used when the data is independent of a particular servlet. Init params should be used when they are specific to a particular servlet.
 
A Dev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
damodar kumar wrote:context param is for entire session of client so if you keep unnecessary things there it will become overhead for application
inti param is for that particular request or response

you need to differentiate where and when we can use those.



Init-param is for specific servlet and context-param is for entire appln.... eve i too know this.

but, what i want to know is when there is context-param, why do we need init-param??? Context-param scores over init-param by being available entire appln. ....

init-param is used when it required for specific servlets.... why can't we use context-param here??? will it be overhead for Appln. if we use context-param??? if so, what sort of over-head???
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a standard data-design procedure: you should give the data to the specific components which need it, instead of putting the data in a global data area which is accessible to all components, whether they need the data or not.

Let's suppose you have a parameter which a specific servlet needs, for example the address of a web service which it connects to. You seem to think it would be an advantage if all servlets had access to that information. I don't agree.

For one thing the other servlets don't have any use for it, so there's no advantage there.

For another thing the other servlets could possibly change or delete it, given bad enough programming, which is a disadvantage.

For yet another thing, if you had 67 servlets which connect to 67 different web services, then if those 67 names were in the global data area you would have to design carefully so that each servlet could tell which value to extract from the global data area. This is a disadvantage too.

So far I haven't seen anything for which putting all of the data in global storage is an advantage. Of course if you have data which applies to the entire application, then naturally that should be put into a place where the entire application can see it. But where's the advantages that you see to storing servlet-specific data at the application level?

(By the way waving your hands at unspecified "overhead" isn't much of an argument. You would have to describe what this "overhead" was, and why it mattered, and why there was significantly more of it when you stored servlet-specific data in the servlet as opposed to storing it in the application.)
 
A Dev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you paul... your explanation is pretty clear. your answer echoed as best possible answer at this moment for my Question.

 
Matthew Brown
Bartender
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another reason to add to Paul's list: you have a servlet specific setting; you make it available to all servlets as a context parameter; somebody else decides to use it in another servlet; you need to change the value...you've just broken the other servlet.
 
A Dev
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Another reason to add to Paul's list: you have a servlet specific setting; you make it available to all servlets as a context parameter; somebody else decides to use it in another servlet; you need to change the value...you've just broken the other servlet.


Hey Methew...

Your answer sounds like giving a string point...but, I didn't understand it clearly... Can you elaborate it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the same global variable problem... if you change it for one, you change it for all. Bad bad idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic