servlets question (reuse )

Discussion in 'Java' started by miko, Sep 18, 2003.

  1. miko

    miko Guest

    Hi ,

    I'm new in this field .
    I wrote simple servlet and now I'm trying to access it from two different clients .
    client a - open servlet , click on button (so the servlet send new page)
    client b - open servlet - get the new page (and not the "welcome" page) .

    I tried to check the cache parameter , but it doesn't use cache .

    any idea ?

    thanks

    miko
     
    miko, Sep 18, 2003
    #1
    1. Advertising

  2. miko

    BrainC Guest

    If I understood correctly what you are trying to do, I can suggest a
    way but I'm not sure 100% it would work.

    You can try creating a static method that holds some kind of variable
    (boolean or string or whatever). When the first client loads page,
    change the variable value and condition the change with loading of the
    new page.

    i.e.

    if (first_client)
    {
    //output original page
    }
    else
    {
    //call the other page
    }

    Hope that put you in the right direction.

    BrainC
     
    BrainC, Sep 18, 2003
    #2
    1. Advertising

  3. miko wrote:

    > I wrote simple servlet and now I'm trying to access it from two different clients .
    > client a - open servlet , click on button (so the servlet send new page)
    > client b - open servlet - get the new page (and not the "welcome" page) .
    >
    > I tried to check the cache parameter , but it doesn't use cache .


    So the behavior described above is what you're getting, but not what you
    want? Then you are storing request- or session-specific information in
    the servlet or in the application context. Most likely the former --
    look for mutable member variables and class variables in your servlet
    class and eliminate them. (Once you understand better how the sevlet
    API works you may find appropriate uses for such, but they are pretty
    much never appropriate in a "simple" servlet.) Use local variables and
    pass them to any helper methods that have need of them rather than
    storing data in the servlet.

    You must always keep in mind that at any one time there is only one
    instance of your servlet class running in the servlet container, and it
    will typically service many requests before being taken out of service.
    The container may use the same one instance for the entire lifetime
    of your application. Servlets should be thread-safe because the
    container may process multiple requests through one instance
    simultaneously. As a hack, a servlet that is not thread-safe can
    implement SingleThreadedModel to force requests through it to be
    serialized, but even then (and either way) you have to make sure that
    one request doesn't change the state of the servlet or application in
    any way that will inappropriately affect other requests from the same or
    another client.


    John Bollinger
     
    John C. Bollinger, Sep 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    5
    Views:
    534
    Steve C. Orr [MVP, MCSD]
    May 17, 2005
  2. Hylander

    To reuse or not to reuse....

    Hylander, Feb 26, 2004, in forum: Java
    Replies:
    0
    Views:
    421
    Hylander
    Feb 26, 2004
  3. danra
    Replies:
    3
    Views:
    327
    Shezan Baig
    Feb 2, 2005
  4. code reuse and design reuse

    , Feb 7, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,025
    Malcolm
    Feb 12, 2006
  5. jacob navia

    To reuse or not to reuse

    jacob navia, Nov 5, 2006, in forum: C Programming
    Replies:
    19
    Views:
    530
    Dave Thompson
    Dec 18, 2006
Loading...

Share This Page