Hello,
I'm new to this list and hopefully it is OK to ask my question here ... ;-)
I'm using FileUpload to get data from a HTML form via POST method
(Apache Tomcat). It works fine, but the encoding of the file is always
damaged. For example, I have text files (XML) in UTF-8 encoding with
german special characters, but when uploading the file and printing its
content to the browser, all special characters are gone or replaced by
something strange.
This is the code I use (avoiding to write the file to the harddisk, I
used the most simple way from the manual):
---------------------
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
String xml = "";
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem fi = (FileItem) iter.next();
if (fi.isFormField() &&
fi.getFieldName().equals("nameCorpus")) {
nameCorpus = fi.getString();
} else {
byte[] data = fi.get();
int c;
for (i = 0; i < data.length; i++) {
c = data[i];
xml = xml + (char) c;
//out.print( (char)c );
}
}// if else
} //while
out.print(xml);
---------------------
It would be nice, when somebody has an idea how I can preserve the
Unicode content of the file ...?
Thank you very much in advance,
Tom
--
Thomas Zastrow
Seminar fuer Sprachwissenschaft
Universitaet Tuebingen
Wilhelm Str. 19
D-72074 Tuebingen
http://www.thomas-zastrow.de
Tel.: 07071/29-73968
Fax: 07071/29-5214
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org