Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session handling in Jsp  RSS feed

 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

How session is handled in jsp ? A interviewer asked me this question.What exactly he meant by this question?
I answered as session is implicit object ,So it will automatically avaliable.or if we make session=false.it will not participate in the session.Does i made any sense.

Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the interviewer was looking for how sessions are maintained by the container.
 
Riya Apate
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I *think* he means to ask about Session Management in JSP:
By default, all JSP pages participate in HTTP session.
The HttpSession object can be accessed within scriptlets through the session implicit JSP object.(This is what you replied...Extention to that
Sessions are a good place for storing beans and objects that need to be shared across other JSP pages and servlets that may be accessed by the user.
The session objects is identified by a session ID and can be stored in the browser as a cookie.
You can store any valid Java object by identifying it by a unique key like this:
<%
Test test=new Test();
session.setAttribute ("test",test);
%>
And you can retrieve it on all JSP pages:
<%
Test newTest= (Test) session.getAttribute ("test");
%>
I am not sure but this might be the answer...
Yeah right..my mistake..
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the replies ..
 
Vijitha Kumara
Saloon Keeper
Posts: 3997
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rujuta gl wrote:
<%
Test test=new Test();
session.putValue("test",test);
%>
And you can retrieve it on all JSP pages:
<%
Test newTest= (Test) session.getValue("test");
%>

Just a little info, putValue and getValue are replaced (deprecated) by setAttribute & getAttribute methods as of servlet 2.2 spec.
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I aswered llike that.but they were not happy with that...I dont know why ..?Any way thanks for the replies....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!