Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Online Exam Problem!!!

 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx William
Bhupendra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic