aspose file tools*
The moose likes Servlets and the fly likes Online Exam Problem!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Online Exam Problem!!!" Watch "Online Exam Problem!!!" New topic
Author

Online Exam Problem!!!

Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Hi
i making online exam problem
from the database i m finding 10 random unique questions
and i m putting them in an ArrayList(i.e. q.nos)
and for respective user i m inserting their session id and
their respective ArrayList.
My program is working very fine...
now i want to get at starting of the exam,user name and
roll no, which will be stored in database i will check for
them if they are correct then i will proceed further otherwise
the same page should appear..
and at the end i have to insert no of marks obtained in
database, for this i need to carry the username and roll no
upto the last question...
to carry this info i may use session object
but i have already used session for storing ArrayList
e.g.
ArrayList a;
...
...
...
session.putValue(session.getId(),a);
now my problem is i want to carry the username upto end ..
how should i do that ??
Could anybody help??
Thanx in advance....
Bhupendra

<B>Bhupendra Mahajan</B>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
You can put any amount of stuff in a session, you just need to use a unique name for each object.
Instead of:
session.putValue(session.getId(),a);
use:
session.putValue( "arraylist",a);
You will automatically get the correct session for each user anyway, using getId() is superfluous. A HttpSession acts like a Hashtable that is automatically managed by the servlet engine.
Bill

------------------
author of:
Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Originally posted by William Brogden:
[B]You can put any amount of stuff in a session, you just need to use a unique name for each object.
Instead of:
session.putValue(session.getId(),a);
use:
session.putValue( "arraylist",a);
You will automatically get the correct session for each user anyway, using getId() is superfluous. A HttpSession acts like a Hashtable that is automatically managed by the servlet engine.
hi William,
i m still confused....
i think session is a common object shared by all users....
that's why i was putting respective session id in session
object...
could u please eleborate more on session..
Bhupendra
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Your session object is unique to each user, that is the whole idea. The servlet container manages sessions by storing the unique ID as a cookie on the user's browser (assuming the user's browser allows cookies). When you use code like:
HttpSession session = req.getSession( false );
The servlet engine looks for the session ID in the request cookies and uses it to find the session object for this user.
The servlet engine also manages the lifetime of the HttpSession object so your system doesn't get clogged by old sessions. In Tomcat, the default lifetime is 30 minutes.
Bill
Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Thanx William
Bhupendra
 
 
subject: Online Exam Problem!!!