Java- HttpSession questions
Q.What is meant by Httpsession and what is the use of sessions ?
Ans: The HttpSession interface is implemented by services to provide an
association between an HTTP client and HTTP server. This session,
persists over multiple connections and/or requests during a given time
period. Sessions are used to maintain state and user identity across
multiple page requests.
HttpSession session = req.getSession(true);
Q. What are the methods in HttpSession and use of those methods?
Ans:
a) getCreationTime()
Returns the time at which this session representation was created.
b) getId()
Returns the identifier assigned to this session.
c) getLastAccessedTime()
Returns the last time the client sent a request carrying the
identifier assigned to the session.
d) getSessionContext()
Returns the context in which this session is bound.
e) getValue(String)
Returns the object bound to the given name in the session’s
application layer data.
f) getValueNames()
Returns an array of the names of all the application layer data
objects bound into the session.
g) invalidate()
Causes this representation of the session to be invalidated and
removed from its context.
h) isNew()
A session is considered to be “new” if it has been created by the
server, but the client has not yet acknowledged joining the session.
j) putValue(String, Object)
Binds the specified object into the session’s application layer data
with the given name.
k) removeValue(String)
Removes the object bound to the given name in the session’s
application layer data.
Q. How do you communicate between the servlets.
Ans: a)servlet chaning
b)Servlet context(RequestDespatcher interface)
Q.Can you send the mail from a servlet ,if yes tell how?
Ans:yes.using mail API
Q.How do you access variables across the sessions.
Ans:Through ServletContext.
Q.where the session data will store?
ans: session objects
Q.What is Servlet Context?
Ans:This object represents resources shared by a group of servlets like
servlet’s environment,Application attributes shared in the context
level.




Leave a Reply
You must be logged in to post a comment.