• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

Servlet Technical Questions

Ok. Here is the scenario....

I have two buttons on a Browser. Both buttons are attached to the same Servlet.

Say Button1, Button2

Button1 clicked - Set of data is transferred to the doPost(). Data is picked up in the doPost() and saved in a GLOBAL VARIABLE(s)
Now the Screen Referfhes
Button2 is Clicked - a Different set of data is transferred to the doPost(). Data is picked up in the doPost() and saved in a GLOBAL VARIABLE(s)

SO here are the questions...
1. Is the same Servlet instance in the Server-Side Container still exists when the second button is clicked? SO that the data I sent via the first click is NOT LOST when the second is clicked?

2. If a another user opens up a brower in his machine while I am working, and goes to the same program, will BOTH SHARE the
save Servlet instance or a different servert?

Thanks
prain
0
prain
Asked:
prain
  • 3
1 Solution
 
bloodredsunCommented:
Firstly you need to define what is meant by GLOBAL VARIABLE(s).

Besides class and instance members/variable, servlets and JSPs have 3 types of storage in memory - request, session, application of increasing levels of persistance.

If you meant storing your data in the session, your answers would be

1./ Yes, the data is persisted across the users page views
2./ Yes and No, the same servlet may be used but the data is kept in a user specific manner

If you meant storing the data in a class or instance member:

1./ Yes
2./ Depends on the load but most probably the same servlet. This is why you do not store information in class or instance members as it is not threadsafe.
0
 
bloodredsunCommented:
Thanks prain.

As a general guide, if an answer is not comprehensive enough to warrant an A grade feel free to ask for clarification so that the experts can at least try to earn an A grade.
0
 
prainAuthor Commented:
Ooops. I did not mean to give a B grade. Probably I clicked the wrong button in a haste.
You, I consider as an expert and my guding light in my development here.

Sorry about that!.

More quesitons coming up.!!! :-)
0
 
bloodredsunCommented:
haha, no probs prain :-)

I've been around here too long to be worried about points all that much but to the newer guys it really helps to get them fighting to answer your questions when you get known as a person would gives A grades for quality answers.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now