Re: Problems uploading a file in UTF-8 using Tomcat / Struts

From: Dave Glasser (dglasser_at_pobox.com)
Date: 01/13/05


Date: Wed, 12 Jan 2005 19:41:34 -0500

sygsix@gmail.com (Robert Bowen) wrote on 12 Jan 2005 09:00:17 -0800 in
comp.lang.java.programmer:

>I am using Struts' FormFile class to upload a text file from a
>multipart form.
>
>Everything works fine in Windoze but now that we have installed it in
>Linux we are getting an error reading the text file, it says it can't
>read it because it is in UTF-8.
>
>We are working in Spanish and as such have characters with accents,
>etc. Do I have to tell Tomcat (in the web.xml with the
>SetCharacterEncodingFilter filter) to treat the file as ISO-8859-1?
>
>I read that this filter is useful when you have a multipart form with
>fields of both type File and normal text fields, so that the normal
>text fields are encoded correctly, but that it doesn't affect File
>fields. And that in order to upload the file correctly I would need
>something like the Jakarta Commons upload utility class. But I imagine
>the Struts FormFile uses commons anyway, no?

I don't know anything about the Struts FormFile class, but I'm
wondering why it would would care about the encoding of the uploaded
text file. The uploaded file should be treated like a stream of binary
data, because, in reality, it could be any type of file--an image, a
Word document, a zip file, etc. Once you get the data uploaded, then
you can use your own code to figure out its encoding and do any
necessary conversions to it.

Sometimes a user's browser is set to use UTF-8 encoding, and form
parameters will be encoded that way, and that can cause problems if
you don't deal with it (especially when you have high-ASCII characters
with accents, etc.) Even if that's the case you're dealing with, I
still don't know why that should have any effect on the uploaded file
data. Like I said, the object that handles reading it from the stream
and possibly writing it to disk should be agnostic about what type of
data it actually is.

-- 
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.
http://qform.sourceforge.net
If you're a musician, check out RPitch Relative Pitch
Ear Training Software.
http://rpitch.sourceforge.net


Relevant Pages

  • Re: Internet Explorer - Firefox
    ... David i have try to change the encoding with all the possible options i have ... If you can do it, create a test folder on your host, and upload the page to ... I imagine it is a problem with how the script is ... suppose to display a search box for flights..i am pretty sure that the ...
    (microsoft.public.publisher.webdesign)
  • Re: Problems uploading a file in UTF-8 using Tomcat / Struts
    ... that the client and server have the same character encoding. ... And that in order to upload the file correctly I would need ... > I don't know anything about the Struts FormFile class, ...
    (comp.lang.java.programmer)
  • Re: Publisher web publishing problems
    ... So then you have to find an encoding to ... support it. ... quotation marks show up as ... > tried to upload older versions of my site and the same errors appear. ...
    (microsoft.public.publisher.webdesign)
  • Re: punctuation other things chaged when publishing
    ... Change your encoding to Unicode. ... and would take a long time to upload. ... images: Compress graphics file sizes to create smaller Publisher Web pages: ... quotation marks, are now little squares, there are little squares at the ...
    (microsoft.public.publisher.webdesign)
  • Re: File uploading with JSP
    ... I submit the multipart form containing the upload to a Perl script (which can ... handle form inputs and multipart data in the same submission), ... file.jsp can then retrieve the values from the query string. ...
    (comp.lang.java.programmer)

Loading