(I haven't tested the following, but I have heard that it works)
I believe the problem is that a different system is used for reading form fields when
a file upload is used. The current Struts system doesn't use the encoding supplied,
so it assumes the default Latin-1 encoding. I believe there is a patch that will use
encoding supplied by the browser (not sure if this works as some browsers may not send
the encoding in some circumstances).
I think there is a work around though. Struts uses Commons Upload to handle the file
uploads through it's own MultiPartRequestHandler. If you replace this with your own
one you can set the encoding as follows:
Struts will use org.apache.struts.upload.CommonsMultipartRequestHandler by default to
handle extracting the parameters out of the request and populating the form. It uses
the DiskFileUpload class from Commons FileUpload. It is that handler that we need to
modify, to do that we could create our own using the
org.apache.struts.upload.CommonsMultipartRequestHandler source as the basis. You will
need to download the source to see how it works.
We need to tell Struts to use ours instead of the defualt by adding this to your
struts-config.xml
<controller multipartClass="my.own.MultiPartClassHandler" />
Then to modify org.apache.struts.upload.CommonsMultipartRequestHandler by creating our
my.own.MultiPartClassHandler class.
We need to modify the handleRequest() method like so:
// Create and configure a DiskFileUpload instance.
DiskFileUpload upload = new DiskFileUpload();
upload.setHeaderEncoding("UTF-8");
// Set the maximum size before a FileUploadException will be thrown.
upload.setSizeMax((int) getSizeMax(ac));
...
Then struts would read the form fields using UTF-8 instead of the default Latin-1
encoding.
struts lover wrote:
Hi Joe,
Which examples.war are you talking about??? I dont see
any examples.war.
All special characters in the text fields get
distorted.
--- Joe Hertz <[EMAIL PROTECTED]> wrote:
Are spanish characters not retained either?
Are you using Tomcat, and if so, are you using the
SetCharacterEncoding
Filter? (Look in the Tomcat WebApps examples.war)
Inquiring minds want to know this stuff :-)
-----Original Message-----
From: struts lover [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 19, 2004 2:48 PM
To: [EMAIL PROTECTED]
Subject: internationalization problem
Hi,
I am facing a problem and trying to solve it for
many
days but in vain.
The user selects the locale(suppose es-spanish)
and
the page displays in that particular locale using
the
appropriate properties file.
I also have a file upload on the same form. I am
using
enctype="multipart/form-data" in the <html:form>
tag.
Now when I enter Arabic text in the text field,
and
post the form, the Arabic text is not retained. It
inserts junk characters.
Can anyone please help me on this issue.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam
protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Jason Lea