• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session handling in jsp

 
Amit Sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to know how can we handle session in two jsp's
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add attributes to the session in the first jsp like this:

<% session.setAttribute(uname,"somevalue"); %>

you can retrieve this object in second jsp as:

<% String username= session.getAttribute(uname); %>

and you can validate the user.

Dont't forget to put <%@ page session="true" %> in both the JSPs.
 
Amit Sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raghu
 
Amit Sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raghu
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead you can use JSTL to add or remome a object from the session.It will provide you more pleasure to your eyes and better maintainablity.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rao raghu:
Dont't forget to put <%@ page session="true" %> in both the JSPs.


By default, a JSP page will automatically create a session for the Request if one does not exist.

The @ page directive is used to prevent a JSP page from automatically creating a session by defining false in code below.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic