Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

passing objects from one jsp to another !!  RSS feed

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I tink you can use de jsp tag FORWARD.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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..
 
Author and ninkuma
Marshal
Posts: 66810
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66810
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
OK, sorry ... I obviously misunderstood the question.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator

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


Huh? Please explain and give example.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!