Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > servlets question (reuse )

Reply
Thread Tools

servlets question (reuse )

 
 
miko
Guest
Posts: n/a
 
      09-18-2003
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
 
Reply With Quote
 
 
 
 
BrainC
Guest
Posts: n/a
 
      09-18-2003
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
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      09-18-2003
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java servlets: Hi All! I want to display xml file in browser using servlets datta.saru Software 0 05-15-2006 03:30 PM
Realtime servlets? Newbie Question Brian Java 5 09-06-2004 01:00 AM
Tomcat 3.3.1a question - servlets not under WEB-INF\classes\ M Java 5 09-19-2003 11:09 PM
Socket/Servlets Question - Please HELP! Keren Java 1 07-30-2003 04:07 PM
Question about servlets Miguel De Anda Java 6 06-30-2003 04:33 PM



Advertisments