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)
Joined: Aug 27, 2002
sorry, i forgot to add this, I DONT WANT TO USE SESSION to pass the objects.. thanks raj
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..
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
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.
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?
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.
Joined: Nov 01, 2002
...pass a serialization of object as a hidden field inside of the form?