• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

passing objects from one jsp to another !!

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, i forgot to add this, I DONT WANT TO USE SESSION to pass the objects..
thanks
raj
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tink you can use de jsp tag FORWARD.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, sorry ... I obviously misunderstood the question.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

...pass a serialization of object as a hidden field inside of the form?


Huh? Please explain and give example.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic