File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes I am in need of help..this is intersting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "I am in need of help..this is intersting" Watch "I am in need of help..this is intersting" New topic
Author

I am in need of help..this is intersting

anand chawla
Ranch Hand

Joined: Oct 19, 2000
Posts: 91
Hi Guys,
Just started working on servlets.needed help.
well i m developing a online exams program.
What i need to do is read 40 records from database
which i m doing successfully.But when i run on network
what happens is when two or more persons start the test
if one person answers the first one..the other person gets the second one straightaway.I have a slight idea why this happens..but would like if anyone explains it to me in better way.also what the solution is.
Thanks
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This kind of problem is almost always because you have member variables declared in your Servlet. You must always remember that the Servlet API is multi-threaded - all client requests use the same servlet, and not store chnageable values in member variables, only in local variables or some context which is not shared between Servlets (such as a Session).


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

Use local variables as Frank suggests or you can also have you servlet implement SingleThreadModel. The servlet container will then create a new instance of the servlet for each request. That is what I did at my first servlet site. It seemed easier than deciding what code had to be syncronized.


SCJP
Visit my download page
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
I would recommend putting each users data into the session. Just remember to clean out the session when they are done so that the next person to use the computer doesn't get all their answers.


- Chris Stehno, SCPJ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am in need of help..this is intersting
 
Similar Threads
multidimensional array assignments
What happens when logout
Comparing ages
CMR Relations one-to-many
Good Java Book??