You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Don Brown (JIRA)" <ji...@apache.org> on 2006/04/25 20:58:46 UTC

[jira] Closed: (STR-316) UTF-16 format character decode error when html-form use enctype as "multipart/form-data"

     [ http://issues.apache.org/struts/browse/STR-316?page=all ]
     
Don Brown closed STR-316:
-------------------------

    Resolution: Fixed

> UTF-16 format character decode error when html-form use enctype as "multipart/form-data"
> ----------------------------------------------------------------------------------------
>
>          Key: STR-316
>          URL: http://issues.apache.org/struts/browse/STR-316
>      Project: Struts Action 1
>         Type: Bug

>   Components: Action
>     Versions: 1.0 Final
>  Environment: Operating System: All
> Platform: PC
>     Reporter: Lee Sure

>
> I want to devolop a chinese version web application use struts.
> Last week, I had tested struts html-tags in weblogic server 6.0sp2. When I used 
> struts-html tags like this:
> <html:form action="/testChinese.do" ENCTYPE="multipart/form-data" method="post">
> <html:text name="testForm" property="text" />
> <html:file name="testForm" property="uploadFile" /> 
> ,
> I had found the chinese characters I got from struts-action all like "??".
> As antitheses, I only used a html-text field to test like this:
> <html:form action="/testChinese.do" method="post">
> <html:text name="testForm" property="text" />
> ,
> the result is OK.
> Test programs lists:
> //testForm.java
> import javax.servlet.http.HttpServletRequest;
> import org.apache.struts.action.ActionError;
> import org.apache.struts.action.ActionErrors;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionMapping;
> import org.apache.struts.upload.FormFile;
> import java.util.Collection;
> public class TestForm extends ActionForm {
>     private String text;
>     private FormFile uploadFile;
> // ----------------------------------------------------
>     public String getText() {
>         return text;
>     }
>     public void setText(String text) { 
>         this.text = text; 
>     }
>     public FormFile getUploadFile () { 
>         return this.uploadFile; 
>     }
>     public void setUploadFile (FormFile uploadFile) { 
>         this.uploadFile = uploadFile; 
>     }
>     public void reset(ActionMapping mapping, HttpServletRequest request) {
>     }
>     public ActionErrors validate(ActionMapping mapping,
>                                  HttpServletRequest request) {
>         return null;
>     }
> }
> // testAction.java
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.apache.struts.action.Action;
> import org.apache.struts.action.ActionError;
> import org.apache.struts.action.ActionErrors;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionMapping;
> import org.apache.struts.upload.FormFile;
> public final class TestAction extends Action
> {
>     public ActionForward perform(ActionMapping mapping,
>                                  ActionForm form,
>                                  HttpServletRequest request,
>                                  HttpServletResponse response)
>                 throws IOException, ServletException 
>    {
>         //response.setContentType( "text/html; charset=GB2312" ) ;
> 		System.out.println("start of TestAction");
>         TestForm testForm = (TestForm)form;
>         try {
>             String text = testForm.getText();
>             System.out.println("&#27721;&#23383; is " + text);
>             FormFile file = testForm.getUploadFile();
>             if (file.getFileSize() > 1024000) {
>                 throw new IOException("&#25991;&#20214;&#36229;&#36807;&#19968;&#20806;&#23383;&#33410;,&#19981;&#33021;&#22788;&#29702;!");
>             }
>             InputStream is = file.getInputStream();
>             InputStreamReader isr = new InputStreamReader(is);
>             BufferedReader br = new BufferedReader(isr);
>             String testStr = br.readLine();
>             System.out.println("get upload file, the first line is " + testStr);
>         } catch (Exception ex) {
>             System.out.println("TestAction has Exception: " + ex);
>         }
> 		return (mapping.findForward("back"));
> 	}
> }
> // test.jsp
> <%@ page contentType="text/html; charset=gb2312" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
> <html:html locale="true">
> <head>
> <title>&#27721;&#23383;&#27979;&#35797;</title>
> <html:base/>
> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
> </head>
> <body bgcolor="#FFFFFF"  topmargin="0" rightmargin="2%" leftmargin="2%" 
> bottommargin="0">
>     
> <!-- content:begin -->
> <table width="100%" border="0" cellspacing="0" cellpadding="0">
> 	<tr>
> 	  	<td width="5%">&nbsp;</td>
> 	    <td width="95%" height="11"> 
> 		    <html:form action="/testChinese.do" ENCTYPE="multipart/form-
> data" method="post">
> 		    <table width="100%" border="1" cellspacing="0" 
> cellpadding="0" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">
> 		    <tr>
>     		    <td height="5" colspan="2">&nbsp;</td>
>             </tr>
>             <tr height="25"> 
>                 <td width="35%" align="right"> &#27721;&#23383;&#26159;: </td>
>                 <td width="65%" align="left"> 
>                     <html:text name="testForm" property="text" />
>                 </td>
>             </tr>
>             <tr height="25"> 
>                 <td width="35%" align="right"> &#19978;&#20256;&#25991;&#20214;: </td>
>                 <td width="65%" align="left"> 
>                     <html:file name="testForm" property="uploadFile" /> 
>                 </td>
>             </tr>
> 		    <tr>
>     		    <td height="5" colspan="2">&nbsp;</td>
>             </tr>
> 		    <tr>
>     		    <td height="5" colspan="2" align="center">
>     		        <html:submit> &#25552; &#20132; </html:submit>    
> 			        <html:reset> &#37325; &#32622; </html:reset>    
>                 </td>
>             </tr>
>             </table>
>             </html:form>
> 		</td>
> 	</tr>
> </table>
> <!-- content:end -->
> </body>
> </html:html>
> // struts-config.xml
> <?xml version="1.0" ?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts 
> Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-
> config_1_0.dtd">
> <struts-config>
>   <!-- ========== Form Bean Definitions =================================== -->
>   <form-beans>
>     <!-- test form bean -->
>     <form-bean name="testForm" type="TestForm"/>
>     <form-bean name="testForm1" type="TestForm1"/>
>     
>   </form-beans>
> 	
>   <!-- ========== Global Forward Definitions ============================== -->
>   <global-forwards>
>     <forward   name="back"                 path="/test.jsp"/>
>     <forward   name="back1"                path="/test1.jsp"/>
>   </global-forwards>
>   <!-- ========== Action Mapping Definitions ============================== -->
>   <action-mappings>
>     <!-- Process a test -->
>     <action  path="/testChinese" type="TestAction" name="testForm" 
> scope="request"
>              input="/test.jsp">
>     </action>
>     <action  path="/testChinese1" type="TestAction1" name="testForm1" 
> scope="request"
>              input="/test1.jsp">
>     </action>
>   </action-mappings>
> </struts-config>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org