Servlet Technical Questions

Posted on 2006-04-05
Last Modified: 2010-04-01
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?

Question by:prain
    LVL 29

    Accepted Solution

    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.
    LVL 29

    Expert Comment

    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.

    Author Comment

    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.!!! :-)
    LVL 29

    Expert Comment

    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.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Need to view directory list in apache/tomcat 9 100
    constructor overloading 2 70
    gZip compression filter 2 74
    oracle fusion vs MQ 2 74
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now