This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have come across this statement on page # 186 in the book HFSJSP:
There is no servlet specific attribute (just use an instance variable).
I understand, we can't create an attribute specific for a particular servlet. However, what does using an 'instance variable' mean? Could anyone explain with an example.
Thanks in advance!
This relates to the scopes of attributes. As they mention the session, request and context scoped attributes, you might ask "how do I define servlet scope attribute?".
This information is an answer. There is no such thing as servlet scope attribute. If you want to achieve something like this, you can define an instance variable in your servlet class. And what does "instance variable" means? Well... it's no rocket science, as you must have passed the OCPJP ;-)
public class A {
private int i; // THIS is an instance variable }
More precisely - they mean this:
public class YourServlet extends HttpServlet {
private int i; // THIS is an instance variable
// Rest of the YourServlet details like doGet(...), doPost(...) and bunch of other stuff
}
Cheers!
OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
When you have the example working, you can just hit F5 and see the counter increasing.
Don't forget that you will probably never use an instance variable in a Servlet, and if you do you have to realize that all requests come to the same servlet, so you need to take care of synchronizing the access (which I didn't do in my example)
hi !!
I have confussion about the session ..
for example
when we login in the G+ , so session starts , when I play games , or comments the same session continues , when I logout the session ends ...
is it so ? or enything more ?
please explain with example if possible...
when we login in the G+ , so session starts , when I play games , or comments the same session continues , when I logout the session ends ...
is it so ? or enything more ?
Yes that is how it works in general. The session ends when you logout or when a time-out occurs (e.g. after 10 minutes of no activity)
There is much more but what book are you studying?
when we login in the G+ , so session starts , when I play games , or comments the same session continues , when I logout the session ends ...
is it so ? or enything more ?
There is much more but what book are you studying?
Regards,
Frits
I prefer head first servlet and java , I am at 5th chapter , but having so many confussion in the end of the 5th chapter.