“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
But one of my friend told me that config is not scope object
Originally posted by Paul Bourdeaux:
You are confusing the config object with the context object. Config is used to access initialization parameters (configured in the web.xml file). You can't write to it because that would mean modifying the web.xml... There is one ServletConfig object per servlet.
Context is shared throughout the web application, and is accessible by every servlet in the web app. This is where you would write the data to be shared.
Check out the ServletConfig and ServletContextAPIs.
Originally posted by Vishnu Prakash:
Because config is not a scope object
1. request
2. session
3. application(context)
4. page
are the only available four scopes, with which you can get and set attributes.
Originally posted by subho saha:
I think the basic way to answer this topic is to point out the difference between Attribute and Parameter.You can set attributes in scope.I.e is you can read and write attributes in context,session ,request scope.But for parameter you can only read them from web.xml bcoz they are fixed except other than request parameter's.
[ October 24, 2005: Message edited by: subho saha ]
Yes but why?
Sorry, I am not able to relate this two.
Originally posted by rathi ji:
Sorry, I am not able to relate this two. Could you please go in bit depth.
Thanks.
Originally posted by Ben Souther:
The context object is not read-only.
Originally posted by rathi ji:
Please look at page 160 of HFS&J.
Originally posted by Adeel Ansari:
Is there anything like context is readonly? I dont think so.
Could you please paste the phrase here.
Originally posted by rathi ji:
Look in ServletContext or ServletConfig and you will find a getter (getInitParameter()) but you will not find setter. There is no setInitParameter().
Originally posted by rathi ji:
If this is the case then why we are not allowed to set attributes in config just like context.
Originally posted by Adeel Ansari:
Because its read-only.
Well, forget about setting attributes in config.
Tell me how would I get attributes from config just like context.
Do we have getAttribute() method in ServletConfig?
We have neither. Actually, there are nothing like attributes in there. It only has initial parameters, which are defined into web.xml, and those are read-only.
After going through the complete discussion. I would like to say that please be rational and ask meaningful questions. Ask when you really want to learn.
[ November 10, 2005: Message edited by: Adeel Ansari ]
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Originally posted by Paul Bourdeaux:
Why we don't have attributes in config like context??
What would you use them for?
Remember, there is only one ServletContext obbject per web application (or per JVM in a cluster). So it makes sense for a servlet to be able to set attributes on the context object so they may be retrieved by other servlets.
However, there is one ServletConfig object for every servlet. If a servlet were able to set an attribute on the config object... the only servlet that could retrieve it would be the same servlet. There is simply no reason for it. Hope that helps.
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Consider Paul's rocket mass heater. |