wood burning stoves 2.0*
The moose likes JSP and the fly likes passing objects from one jsp to another !! 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 "passing objects from one jsp to another !!" Watch "passing objects from one jsp to another !!" New topic
Author

passing objects from one jsp to another !!

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hi all,
is it possible to pass an Object from one jsp page to another on form sumbit ?? wat i want is, when a click on the link of jsp page i want to submit a form and pass an Object which i have created in the first page to the second page..on clicking on the link, i called a js function and submits a form whose action tag is to the second page !! is there any other method ??
thanks
raj


SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
sorry, i forgot to add this, I DONT WANT TO USE SESSION to pass the objects..
thanks
raj
Bernard Fred
Greenhorn

Joined: Jul 17, 2003
Posts: 3
I tink you can use de jsp tag FORWARD.
kalpana Kumar
Ranch Hand

Joined: Jul 03, 2003
Posts: 65
Hi
You can use forward(req,res).
For Eg:-
Say U want to pass a bean
request.setAttribute("xxx",bean);
RequestDispatcher rd;-this is for the particular jsp page to which control is to be transferred.
Then use
rd.forward(req,res);
To get the reference of the bean u can either use <jsp:usebean> tag or
(typecast)request.getAttribute("xxx");
Hope this helps..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65


pass an Object from one jsp page to another on form sumbit ....
I DONT WANT TO USE SESSION to pass the objects

Then you are out of luck. A forward will not help you since that will just forward to the new JSP page within the context of the same request (in other words, no form submission).
You can pass text data across the request context change via request parameters, but not objects.
So except for tacking objects onto the session or servlet context, there's no practical way to preserve object instances.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Couldn't you store the object reference in request scope?
request.setAttribute("xxx", yourObject);
then do your forward, then on the target page
<jsp:useBean id="xxx" type="YourObjectType" scope="request"/>
to get access to it.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
You can pass text data across the request context change via request parameters, but not objects.

So request.setAttribute("whatever", Object) will not work. Try it using this in the calling JSP and request.getAttribute("whatever") in the called JSP and you will see that the object is null (at least in my experience this has been the case). If you are really determined you could Serialize the Object to file but the object you are trying to pass must be serializable (obviously).


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60773
    
  65

Couldn't you store the object reference in request scope?

No. If a form submission is to happen, the first request context has long gone out of scope and a new request is created when the form is submitted.
hth,
bear
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
OK, sorry ... I obviously misunderstood the question.
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
Couldn't you go simpler, and pass a serialization of object as a hidden field inside of the form?
If worst comes to worst, you could pass the parameters as hidden text fields inside the form, and reconstruct the object again on the other side.
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
...pass a serialization of object as a hidden field inside of the form?

Huh? Please explain and give example.
 
wood burning stoves
 
subject: passing objects from one jsp to another !!
 
Similar Threads
Problem in accessing request object in child frames.
Cannot set attribute in request in jsp
Passing array of checkboxes from one JSP to another
Passing Multiple Values to another jsp page from a List Box
passing an object from one controller to another