jsp - Java Servlet how to get a specific value from a session attribute -
ok, i'm kind of inept @ explaining problems, i'll try detailed, yet concise possible.
i have 2 servlets; newcustomerservlet , loginservlet
i have 1 java bean; user
the user has bunch of fields. username, firstname, password, etc...
my index.jsp automatically directs user newcustomerservlet, user can create "account" once finish filling in fields user bean created , saved in session. then, user able "login"
the problem i'm having validating username "user" session login.jsp fields using session.
how access sessions "username" or "password" field. can seem access name of session, "user"?
referencing javadoc httpsession,
you realize httpsession
stores attributes key, hashmap
, place objects in session (any serializeable object) like:
string username = "something";// session.setattribute("username", username);
then can out using:
string un=(string)session.getattribute("username");
it possible store more complex objects, entire user
object, long object implements serializable:
user someuser = //details left op session.setattribute("user", someuser);
then can later retrieve information user:
user someuser = (user)session.getattribute("user"); if(user != null){ string username = user.getusername(); }
also, here nice, brief run-through of common session utilization servlets
, httpsession
: session tracking
Comments
Post a Comment