• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Online Exam Problem!!!

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx William
Bhupendra
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic