Java, HTML forms and encodings

I had to make a java application that uploads images to a PHP web application, along with some information about it. There’s also a web interface for administration with the same purpose… So I made the java application talk to the administration interface via HTTP POST.

The Jakarta Commons Httpclient is a nice tool for performing these tasks. Specifically, the multipart post method does the trick.

However, if your data contains, or you think it might contain, characters in a “non-default” encoding, you should make use of the Part interface, instead of using the simpler addParameter() methods. That will allow you to specify the encoding for your data, using the tree-argument constructor for StringPart, which allows to specify a particular encoding.

In my case, that meant “ISO-8859-1“.


%d bloggers like this: