Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is there any way to pass objects throw http params ?

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but way this code dont work even if i do :
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i see what do you mean by "context scope"
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
context scope == application scope.

Objects bound to context scope last the duration of the application.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry ignor , i used clone()
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic