Re: Problems uploading a file in UTF-8 using Tomcat / Struts
sygsix_at_gmail.com
Date: 01/14/05
- Next message: Chris Berg: "Re: AppletContext.showdocument() vs. popup-blockers"
- Previous message: WOJSAL: "JasperReports in text mode"
- In reply to: Dave Glasser: "Re: Problems uploading a file in UTF-8 using Tomcat / Struts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 14 Jan 2005 04:32:07 -0800
Hi there, thanks for the response.
In the end I figured it out, with a little help from Google Groups. It
turns out our Red Hat Linux is installed in english, UTF-8. My web
pages, the the file we are uploading are both encoded in ISO-8859-1. We
changed the file:
/etc/sysconfig/i18n
so that is uses ISO instead of UTF et voila.
We *should* be able to control it in our Webapp, and in fact we tried
changing all kinds of things, from the web.xml (putting a
javaEncoding=ISO-8859-1 as an init param for the Struts Action
Servlet), to changing our Actions so it changed the encoding scheme of
the request object. And nothing worked.
I read in one of the messages that we shouldn't rely on this, that we
should "defend" from these kinds of problems in the app, and not assume
that the client and server have the same character encoding.
Specifically it was suggested that when you create a FileInputStream,
or BufferedInputStream, or whatever object you use to read an uploaded
file, that you set the character encoding first. All well and good but
since we are using Strut's FileForm, which I think uses the Jakarta
commons FileUpload classes, it wasn't that simple to make that change.
I took a brief look at the FileForm class and didn't see anything about
encoding. And since we've been struggling with this problem the whole
week, and our client is starting to get p'd off ...
Anyway, it's all in the interest of learning, no? And getting paid ...
Thanks again, cheers!
syg
Dave Glasser wrote:
> 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
- Next message: Chris Berg: "Re: AppletContext.showdocument() vs. popup-blockers"
- Previous message: WOJSAL: "JasperReports in text mode"
- In reply to: Dave Glasser: "Re: Problems uploading a file in UTF-8 using Tomcat / Struts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|