I need to send a Java object from my Java program to Servlet. I thought of doing it by serialization. Is there any other thing I can use to send a Java objec开发者_开发知识库t to Servlet. If it is by serialization can you give me the link for reference.
Thanks for the help
Use an HttpURLConnection, create a POST request, and before connecting to the server, get the outputStream from the HttpURLConnection, wrap it with an ObjectOutputStream, and write your object to it.
You will have to do the reverse on the server side.
The potential problem with sending serialized Java objects is that the client and webserver need to both have the right versions of all of the classes for all of the objects involved.
That's OK if you have control over the client and server sides and the ability to deploy new versions at will. However, if you don't a better option might to be use JSON or XML instead of serialized Java objects.
Consider RMI. It sound like that to me.
Take a look at the following:
http://www.javaworld.com/javaworld/javatips/jw-javatip103.html http://www.cs.unc.edu/Courses/jbs/lessons/java/java_serialization/serverThreadedCO.html
Hope this helps
Have a look at Hessian: http://hessian.caucho.com/
We use Hessian to send serialized Java objects from our Java rich client to our servlet. Hessian can also be used in conjunction with the Spring framework.
精彩评论