aspose file tools
The moose likes Applets and the fly likes Applet -Servlet Communication (geting & sending values) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Applets
Reply Bookmark "Applet -Servlet Communication (geting & sending values)" Watch "Applet -Servlet Communication (geting & sending values)" New topic
Author

Applet -Servlet Communication (geting & sending values)

Claude Nichols
Greenhorn

Joined: Oct 25, 2001
Posts: 7
hello ranch,
I'm trying to duplicate the normal function of a search, but using an applet. The user enters search requirement in the applet and requests the serlvet to send back results to a list.
However I don't know how to send parameters to the servlet from the applet. How can this effectely be done
NB. Student please keep consider the use of terms
Anyone suggestion
thank you in advance
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14573
    
    7

Use the URLConnection class to allow the applet to submit a server request and receive its response. A good book on java network programming should have an example. The code is the same for both Applications and Applets except for things like sandbox limitations (you can only talk to the server the applet was loaded from).


Customer surveys are for companies who didn't pay proper attention to begin with.
guggilla reddy
Greenhorn

Joined: Oct 29, 2001
Posts: 2
Sir I want to know the complete details of Applet-servlet communication.
Claude Nichols
Greenhorn

Joined: Oct 25, 2001
Posts: 7
Thanks for your replies,
I used the URLconnection and it works to a point in sending lower level objects eg String.
The applet must call the servlet which intern searches a database and return the result in the form of a ResultSet object.

My tutor wants the servlet to pass the ResultSet object to the applet for the applet to take care of how results are formatted.
Ques. 1 Can a ResultSet object be serialized
2 how can this object be passed to the appplet without throwing a throwing a java.io.notSerializableException

Hey guess gotr any ideas
sabbir kazi
Ranch Hand

Joined: Feb 03, 2001
Posts: 62
You may create a serializable class (on both applet and servlet) that can hold all your data. Populate that class object with ResultSet values, then pass that to the Applet using writeObject method. In applet side, you can read this object in your similar class object.
Sabbir
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14573
    
    7

Serialization over HTML is a Bad Idea. The Java serialization form is a binary form, and years of pain have taught me that about the only time binary data is a good idea is for compressed files and executables.
More critically, however, the serialization formats vary between different Java versions and therefore may be indigestible (beginning to see where the pain came from?).
Also, the ResultSet couldn't be serialized meaningfully anyway - it contains a dynamic environment that extends all the way back into what is most likely non-Java code (the database server). Finally, the ResultSet is very likely to be using a TCP linkage to the database for JDBC which will run afoul of both applet sandbox and network firewall.
You're much better off using text. It's universal and portable, and modern storage and transmission protocols make sure it's handled efficiently in a transparent manner (binary could actually present "worst-case" incidents to those mechanisms and thus void the major so-called "justification" for using binary).
For simple data, a row-per-line file format is sufficient. For more complex structure, there's XML. As a side benefit, you can more easily debug the data stream, since it's all human-readable.
Claude Nichols
Greenhorn

Joined: Oct 25, 2001
Posts: 7
Thank you for your responces
I have found out that sending other complex objects works. however when trying to send ResultSet by itself of within a serialized class the error is thrown in the servlet and the applet with the message java.io.notserializableException
I guess ResultSet carries with it some other in-built objects which would cause java security rules to be compromised.
Explaining why the writeObject method throws the exception when it encounters ResultSet

Anyway Guys thanks a million
Nishith Prabhakar
Greenhorn

Joined: Jul 25, 2001
Posts: 12
notserailzable is not a security exception.
Its coz the resultset object you are using cannot be converted to binary ... which is a requirement for the writeObject method.
Make a subclass of the ResultSet class and implement the interface Serializable. Pass the new class between the applet and the servlet. Should work.


-----BEGIN GEEK CODE BLOCK-----<BR>Version 3.1<BR>GCS/CC/IT d->+ s: a-- C++(++++)$ ULH+>++++ P>P++ L+(++)$ E+ W+(++) N+>++ o? K? w++>+++<BR>O--- !M V? PS+(-) !PE Y+ PGP->+ !t !5 !X R->* !tv b+>+++ DI !D<BR>G+(++) e>+++ h@ !r y-*<BR>------END GEEK CODE BLOCK------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet -Servlet Communication (geting & sending values)
 
Similar Threads
JDBC and Applets
applet send arabic to servlet
servlet to applet communication
Writing Image from Applet
servlet applet commnication