File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Passing objects via form submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing objects via form submit" Watch "Passing objects via form submit" New topic
Author

Passing objects via form submit

Sunil Kumar Jakkaraju
Greenhorn

Joined: Oct 06, 2006
Posts: 24
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?


Thanks & regards,
Sunil
When all else fails, follow instructions. - Allen's Axiom
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

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

Joined: Oct 06, 2006
Posts: 24
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

Joined: Jan 10, 2002
Posts: 60991
    
  65

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

Joined: Apr 02, 2004
Posts: 884
If he uses web services, think he should be able to?


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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

Joined: Apr 21, 2006
Posts: 1847
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.


42
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


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

Joined: Feb 07, 2004
Posts: 472

Serialize and use URL encode maybe applying something like 64base up front.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing objects via form submit