hi all, please help me its simple but i am not getting where i am making mistake problem: when i am calling httpsessionservlet (myfile) through two different browser that means two different client they are sharing session that means they are incrementing same value of i client-1 increments i - 1,2 then client-2 increments -3,4 code is here //*** html file html> <form action="http://192.168.1.23:7001/MyWeb/httpsessionservlet.com">
Enter book name: <input type=text name="bname"> <input type=submit name="sub" value="Submit">
If you are going to post more than a line or two of your code, wrap that code in a set of UBB Code tags. Doing so will help to preserve your code's indenting, making it easier to read. If it is easier to read, more people will actaully read it and you will stand a better chance of getting help with your question.
How are you opening the second instance of your browser?
Joined: Dec 07, 2005
thaks for reply,
i am opening new browser , i am not using ctrl+n even if i call that servlet from different machine then also session is get shared bet them and one more thing if insted of 'i' if i am passing bname that time it works fine
Ahh, I did not read your code closley enough the first time (as the tip hinted, I usually skim past unformatted code).
Your sessions are not being shared. You're writing to instance variables from your service methods. This means your code is not thread-safe and the problem you're having is a result.
A simple rule of thumb to follow (until you fully understand threading in servlet apps): Never use instance variables. Declare all of your variables in your service (doPost, doGet) methods. [ June 30, 2006: Message edited by: Ben Souther ]
Joined: Dec 07, 2005
thanks... for reply
one object multiple instance or multiple thread and all thread shares instance variable of that object on which thread is created
web container doesnot provide any concurrency control for the servlet. If any part of servlet or the data being modified,in order to provide the concuurency control this is the resposneblity of the developer. u can put the data which is required to be thread safe keep it in the sychronize block.
On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it; specifically, a first name and a last name are required. Please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.