Skip to content Skip to sidebar Skip to footer

How To Send An Image From A Java Applet To JavaScript?

I have a Java Applet that is generating an image. Ultimately, I would like to insert the image data into a database, so I want to temporarily store the image data in a form field o

Solution 1:

You have basically 2 options:

  1. Encode it from byte[] to String using Base64 so that the binary data won't be malformed when being transferred as character data. Then, let JavaScript set it as some hidden input value of some POST form. In the server side, you need to Base64-decode it to get the original byte array back.

  2. Use Java to fire a HTTP POST request programmatically inside the Applet. The Java SE API offers the java.net.URLConnection for this (little tutorial here). A more convenienced API is the Httpclient. In the server side you just need to handle it as a regular POST request parameter.

It's unclear what server side programming language you're using, so I can't give a more detailed answer for that side.


Post a Comment for "How To Send An Image From A Java Applet To JavaScript?"