servlets question (reuse )

M

miko

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
 
B

BrainC

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
 
J

John C. Bollinger

miko said:
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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top