This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Refresh Using setheader on response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Refresh Using setheader on response" Watch "Refresh Using setheader on response" New topic
Author

Refresh Using setheader on response

robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102
Hi

I have a web application which is totally servlet based, when i use the



and deploy my code on my local machine and let other clients access the application deployed on my machine. Everything works just fine before the refresh but after 15 seconds the last changes made by one client are reflected in all the machines. What i want is when page refresh takes place it do so, not affecting the other clients.

There was one more observation when one logs out. The other client browser says your session is expired.

I have used



where hs is declared private to get the session.

About the structure of my app : I am using four java classes one represents home page,one authorizes and takes to the main page of application and one is for signing out.

Thanks & Regards
Robin


Life is short play hard.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I sounds like you maintain state (ie have instance variables) in your servlet. If you do, remove them immediately please! These values are shared and therefore written by one a then read by others.
robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102
It means i should make all variables local to a particular function and pass parameters as & when required rather than declaring class or instance variables???

Thanks
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

Do not ever declare instance variables in Servlet since they will share their values for all the clients who access the same servlet. Always declare local variables in methods and pass them through parameters to other methods.


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Correct.
robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102
Hi
As asked i removed all instance variables from the 4 servlets i am using but still i am facing the same problem as before.

I am explaining my application in more detail (what exactly i am doing):

1st Servlet -- I am displaying the home page which will send username and password to the 2nd Servlet;

2nd Servlet -- Checks the parameters and if username pass. correct then redirects to 3rd Servlet.

3rd Servlet -- Now here is All the stuff happening in doget() and doPost() i am calling various method which connect to database and retrieve values and pass on to other methods. Now everything is local. I am passing values as parameters to different functions. Here i have used setHeader in both get and post requests. Now when i click signout here it takes me to 4th servlet.

4th Servlet -- It invalidates the session redirects to the 1st Servlet.

Thanks
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Is it working better now?
robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102
Yes it is working now thanks all for the info.

Regards Robin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refresh Using setheader on response
 
Similar Threads
Is the HttpSession per Tomcat session or per client?
Problem while using session for transferring huge data from controller to session
JOptionPane halts RMI thread
session object behaves like application (scope)
How 2 jboss communicate with each other ?