*
The moose likes JSP and the fly likes session handling in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "session handling in jsp" Watch "session handling in jsp" New topic
Author

session handling in jsp

Amit Sharma
Ranch Hand

Joined: Nov 22, 2005
Posts: 87
i want to know how can we handle session in two jsp's


Amit Sharma SCJP 1.4, SCWCD 5, OCUP-100(UML)
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100
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.


RAGHU<br /> <br />"When the going gets tough, the tough get going"
Amit Sharma
Ranch Hand

Joined: Nov 22, 2005
Posts: 87
Thanks Raghu
Amit Sharma
Ranch Hand

Joined: Nov 22, 2005
Posts: 87
Thanks Raghu
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
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.


~Sanjeev Singh<br />SCJP 1.5
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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.



Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session handling in jsp
 
Similar Threads
Alternative to Cookie?
Field set in action method coming null in JSP
Advice on persisting complex state across multiple server trips
ASP
Session problem in NetBeans