Forums Register Login

Passing an object as a part of Form Post - Possible?

+Pie Number of slices to send: Send
Hi all,
Can we pass an object as part of a form post from an html page? I would like to create an Object using my JavaBean and pass it to the JSP along with the form fields.
Is this possible?
Thanks in advance,


------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
+Pie Number of slices to send: Send
how are you going to embbed (so to speak) the object inside of a form field ??..there are only so many types of attributes that a form can have (text, radio etc)
but if u think you can do that then its no problem coz any data inside of a form can be posted to the server
you can use file upload as an example, its almost always inside of a form (just with a diff encoding type) and when its posted you can easily read the content off the input stream...
-manav
+Pie Number of slices to send: Send
Hi manav,
Am sorry for not making my query comprehensive.
You see, if we use METHOD=POST, there is no restriction on the data that could be posted to the server.I am assuming also, that any type of objects could be posted to the server.Correct me if I am wrong.
We generally post the form fields to the server.I wanted to explore, if I can also post some objects apart from the form field data.The object could be made available through the JavaBean in the JSP page.
So,my query is - "is posting form field data PLUS object(s) created by the JavaBean method to the server possible?"
Regards,
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 26, 2001).]
+Pie Number of slices to send: Send
anything you pump into the output stream can be read at the server..how the 0bject is packed and unpacked is upto you
but you see at a more basic level form can only have certain attributes i don't see how you can have a object inside a form..we use forms to pass data to the server (instead of using the session object) but those are basic datatypes like strings and numbers (stuff form fields can contain)...
i hope i communicated well?
-manav
+Pie Number of slices to send: Send
You are correct when you say that you can pass any kind of data in a POST input stream. However, to put a Java object in the stream, you need a Java Virtual Machine running on the client. With an applet, you have a VM. But when a browser is displaying an HTML form, where is the VM?
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com
+Pie Number of slices to send: Send
Why do you want to pass a java object THROUGH a form from one jsp to another? Generally HTML form has some standard set of input controls like TEXTFIELD,RADIO,CHECKBOX,HIDDEN,SUBMIT,LIST etc. If you want to pass an object from one jsp to another use request,session,application scoped vars.
May be we don't really get what's your real requirement is.
regds
maha anna
+Pie Number of slices to send: Send
Hi all,
Thanks very much for the response.
We had a very simple requirement to pass the Resultset Object, which was obtained by one of the methods of the Java Bean.This had to be posted along with the Formfield data.
The Resultset Object along with the form data was required by another JSP.We had 2 options to do it.

  1. Process the Resultset in first JSP itself.
  2. Use the setAttribute() of request,session or application implicit objects, as Maha anna has suggested
  3. Pass the Resultset object to another JSP along with the form fields.

  4. Wanted to explore the third option, as our second JSP was specifically designed keeping this in mind.
    Our problem was how to append that Resultset Object to the URL, after the user enters the form field data, i.e. how do I trap the URL when the user clicks "Submit",append the Resultset object in this fashion...

    ...and then post the data to another JSP.
    Can this be done?Or have I missed something?
    Thanks for your views.
    Regards,
    Sandeep Desai
    vgdesai@bom3.vsnl.net.in

    1. Sun Certified Java Programmer Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

    5. [This message has been edited by Desai Sandeep (edited April 27, 2001).]
+Pie Number of slices to send: Send
 

Originally posted by Desai Sandeep:
[B]
I think u can do with proper type casting.
Anil

 
+Pie Number of slices to send: Send
Hi,
Can we trap the URL after the user clicks the Submit button and before the data is posted to the other JSP?
Thanks in advance
Regards,

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 27, 2001).]
+Pie Number of slices to send: Send
 

Originally posted by Desai Sandeep:
We had a very simple requirement to pass the Resultset Object, which was obtained by one of the methods of the Java Bean.


It is bad practice to allow "live", connected ResultSet objects to venture anywhere outside a try... finally block. If you must, use a disconnected buffer such as a Collection or a javax.sql.CachedRowSet.
There certainly cannot be any question of passing a ResultSet between JVMs, let alone between a server and a browser and back. Even if a ResultSet were Serializable -- it is not -- all the state of the database connection would be transient, and lost upon deserializing the ResultSet.



  1. Process the Resultset in first JSP itself.
  2. Use the setAttribute() of request,session or application implicit objects, as Maha anna has suggested
  3. Pass the Resultset object to another JSP along with the form fields.


The first option is preferable by far. The second works, but violates good practice as indicated above, because (a) it is a potential source of resource leaks (b) hogs a database connection for longer than necessary and (c) couples two separate Java classes (the JSPs) much too tightly. The third is impossible.
There is a fourth option -- refactoring. I don't know the details, but it sounds as if there is something fundamentally flawed about what you want to do. If your first JSP is about setting up a data query, then it should not be a JSP but a combination of a servlet and Java classes, JavaBeans, or EJBs. For example, instead of passing an open query from one JSP to the other, you could pass a request- or session-scoped query object that contains enough information and code to run the query the moment you need the data. This addresses all concerns mentioned above in one go: (a) since you delay firing the query until you actually need the data, you can protect it with a try... finally block (b) for the same reason, the connection is used as briefly as possible and (c) the query object acts as a well-defined interface between the two jsps/servlets and moves all the database access code out of them.
This is just one possible solution. There are at least half a dozen others (such as using a session EJB to hold the query state and provide a facade for the data access).
- Peter
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1058 times.
Similar Threads
Just read this article. This is how C# developers compare their language with Java.
Saving an HTML file generated by the JSP on the Server - Possible?
Does the IBM 486 test offer a cert?
Implementing an interface in JSP- Possible?
Deploying JSP in Oracle 8i - Any Benefits?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:26:58.