• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Init-Params and COntext-Params

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 77
Android MyEclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Sheriff
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic