• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing objects via form submit

 
Sunil Kumar Jakkaraju
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ArrayList object in a JSP page. I would like to pass it to another JSP page that is being served on another web app server.

I cannot set the object on the session object.

I'm submitting the form using JavaScript.

How do I do it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. The JSP is executed on the server and your array list object goes out of scope long before the user gets a chance to submit the form on the client.

Please read this article for a better understanding of how JSPs operate.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sunil Kumar Jakkaraju:

I cannot set the object on the session object.


Sure you can. It's easy.
 
Sunil Kumar Jakkaraju
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

I might not have framed my question properly.

What I need to accomplish is to submit a request to another web server from a JSP page.

Initially, at the time when the JSP page is rendered, it gets an ArrayList object. This object has to be passed while requesting to another web server. This object can be retained in the page by setting it to session. But it is not enough when this object needs to be passed to different web application running in different web server.

A URL http://anotherwebserver ortno/anotherwebapp/SomeServlet is called from a javascript submit. This servlet does some background processing using the ArrayList object.


How can this be done?
[ December 09, 2006: Message edited by: Sunil Kumar Jakkaraju ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You most definitely cannot pass an object from one server to another. The only means you have is to pass data as request parameters.

If you are submitting a form, you can set the values into hidden elements.
[ December 09, 2006: Message edited by: Bear Bibeault ]
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If he uses web services, think he should be able to?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we back up a minute here.
Although the original poster thought in terms of passing an ArrayList object, lets think of just passing an ordered set of values. That could be as simple as hidden form values with names that transmit the order.



etc etc

Naturally the target web app will have to extract the form values and put them in order in a new ArrayList object.

Bill
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chengwei Lee:
If he uses web services, think he should be able to?


Using something like SOAP you can, but that's quite different from submitting a form through a JSP.
And just like RMI calls you're not in fact passing an object, but rather you're serialising an object and thus passing a copy of that object.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen T Wenting:

... but rather you're serialising an object and thus passing a copy of that object.


More specifically, you're passing a textual (XML) representation of that object's data.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serialize and use URL encode maybe applying something like 64base up front.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic