Hi !

        I don't if it will fit into your needs but, to handler UTF-8 I
build a serverlet filter with handles all encode / Decode operations. As
far as I know this approach is not a pure Struts solution but works
really fine !
I didn't test with a upload form like yours, but itís a shot !

Regards

  Josť Gustavo Zagato Rosa
System Analyst - Atos Origin
[EMAIL PROTECTED]


-----Original Message-----
From: Paul Barry [mailto:[EMAIL PROTECTED] 
Sent: terÁa-feira, 28 de outubro de 2003 12:07
To: [EMAIL PROTECTED]
Subject: Problem with UTF-8 characters in a mutlipart/form-data encoded
form

I am using Struts 1.1 in an application that needs to support the UTF-8
character set.  I am using Resin 2.1.10 with 
character-encoding="UTF-8", and on most of my forms this seems to work
just fine.  I am having problems with forms that 
have to use the multipart/form-data enctype for handling uploading
files.  If I print out the value of a text element in 
an html:form where the enctype is not set at all (which ends up using
application/x-www-form-urlencoded), using UTF-8 
characters works fine.  This is what I get:

INFO - test.TestAction - The value is: š

Here is what the actual HTTP request that gets sent to the server looks
like:

--- Start HTTP Request
-----------------------------------------------------
POST /testForm.do HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, */*
Referer: http://pbdesktop/test.do
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: pbdesktop
Content-Length: 11
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: SERVER=op; locale=en_US; JSESSIONID=aoUCARQpqsLd

test=%C3%AD
--- End HTTP Request
------------------------------------------------------

But if I modify my html:form to use enctype="multipart/form-data", I get
this:

INFO - test.TestAction - The value is: A§

And the HTTP request looks like this:

--- Start HTTP Request
-----------------------------------------------------
POST /testForm.do HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, */*
Referer: http://pbdesktop/test.do
Accept-Language: en-us
Content-Type: multipart/form-data;
boundary=---------------------------7d319628600e4
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: pbdesktop
Content-Length: 141
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: SERVER=op; locale=en_US; JSESSIONID=aoUCARQpqsLd

-----------------------------7d319628600e4
Content-Disposition: form-data; name="test"

í
-----------------------------7d319628600e4-
--- End HTTP Request
------------------------------------------------------

It looks as if the character is already messed up before it even gets to
the servlet container.  There are messages in 
the mailing list archive that discuss this problem, but I didn't see a
solution.  What is the best way to handle UTF-8 
characters in a multipart/form-data encoded form?

Here is the code that I am testing with:

/test/test.jsp:
<%@ taglib uri="WEB-INF/taglib/struts-html.tld" prefix="html" %>
<%@ taglib uri="WEB-INF/taglib/struts-bean.tld" prefix="bean" %>

<html:html>
   <body>
     <html:form action="testForm.do" enctype="multipart/form-data">
       <html:text property="test" />
       <html:submit />
     </html:form>
   </body>
</html:html>

Relavent parts of struts-config.xml:
<struts-config>

   <form-beans>
     <form-bean name="testForm" type="test.TestActionForm" />
   </form-beans>

   <action-mappings>
     <action path="/test" type="org.apache.struts.actions.ForwardAction"
parameter="/test/test.jsp" />
     <action path="/testForm" type="test.TestAction" name="testForm"
input="/test.do" scope="request" />
   </action-mappings>

   <controller contentType="text/html;charset=UTF-8" />

<struts-config/>

test.TestAction:
package test;

import javax.servlet.http.*;
import org.apache.commons.logging.*;
import org.apache.struts.action.*;

public class TestAction extends Action {
        private static final Log log =
LogFactory.getLog(TestAction.class);
        
        public ActionForward execute(
                        ActionMapping mapping,
                        ActionForm pform,
                        HttpServletRequest request,
                        HttpServletResponse response)
                        throws Exception {
                TestActionForm form = (TestActionForm)pform;
                log.info("The value is: "+form.getTest());
                return null;
        }
}

test.TestActionForm:
package test;

import org.apache.struts.action.ActionForm;

public class TestActionForm extends ActionForm {
        private String test;
        public String getTest() { return test;  }
        public void setTest(String string) { test = string; }
}


---------------------------------------------------------------------
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]

Reply via email to