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
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.
Sir I want to know the complete details of Applet-servlet communication.
Joined: Oct 25, 2001
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
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
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.
Joined: Oct 25, 2001
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
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.