wood burning stoves 2.0*
The moose likes JSP and the fly likes is there any way to pass objects throw http params ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "is there any way to pass objects throw http params ?" Watch "is there any way to pass objects throw http params ?" New topic
Author

is there any way to pass objects throw http params ?

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Hello
say I like to pass object I created in one page say : MyObject obj = new MyObject("1","2","3");
via http params (supmit or post ) to other page . and use it there can it be done ?
nizams uddin
Greenhorn

Joined: Jul 31, 2006
Posts: 15
pass the object after storing in a HttpSession.getSession().setAttribute("anyname","Myobject");

In the next page (where ever you want to access)
MyObject myobj = (MyObject)HttpSession.getSession().getAttribute("anyname");
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
ok thanks
tell me please if I use this kind of way to use paramets:



I can access the object[] elements but I way I cant get the object[] length ?
is it good methods to pass objects? if I need to avoid using sessions?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Meir Yan:
Hello
say I like to pass object I created in one page say : MyObject obj = new MyObject("1","2","3");
via http params (supmit or post ) to other page . and use it there can it be done ?


Well, you can pass only string objects via parameters. For your custom objects and other objects, use attributes.
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
but way this code dont work even if i do :
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410




A request only lasts long enough to return one page.
Then it's gone.
When the user submits the form on that page, a new request is generated.
That new request isn't going to have any of the attributes from the old one.
You either need to save the information in a longer lasting scope (session or context scope) or find a way to serialize that object into a string that can be written to the page as a hidden input field.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
ok i see what do you mean by "context scope"
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

context scope == application scope.

Objects bound to context scope last the duration of the application.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why are you avoiding session?
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
no its ok i will use sessisons
one more question when i trying to copy the the contant of the object
to other object im geting error here is my code now and its working fine until i try to copy the object[] to object[]

do i need to use System.arraycopy ? is this the only way?
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
sorry ignor , i used clone()
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why are you copying/cloning the array?
If you're binding it to session you should be able to work with the same array from both pages..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is there any way to pass objects throw http params ?
 
Similar Threads
Passing values in a form with multiple actions
HTTP - tunneling and Objects..
Passing parameters to jApplet
spaces between categories in cewolf barchart
calling value from servlet in jsp