commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Atlas" <MAt...@basistech.com>
Subject RE: Help with JSP parsing form data for UTF-8 charsets?
Date Tue, 07 Feb 2006 19:56:18 GMT
Hello,

I found a fix for this.

Hi everyone:

Here's some good information here that solved my problem of processing multipart form data
containing UTF-8 (unicode) characters in Commons FileUpload:

http://www.theserverside.com/discussions/thread.tss?thread_id=28944

Here's a snippet of my code that processes the UTF-8 form data using Commons FileUpload:

http://java.pastebin.ca/40594

The most important lines are 9 and 26:

upload.setHeaderEncoding("UTF-8");
...
String value = new String(item.getString().getBytes("ISO-8859-1"), "UTF-8");
...


-----Original Message-----
From: Michael Atlas [mailto:MAtlas@basistech.com] 
Sent: Tuesday, February 07, 2006 2:01 PM
To: Jakarta Commons Users List
Subject: RE: Help with JSP parsing form data for UTF-8 charsets?

Hi Martin. Thanks for the quick response. I have recently added that to my my HTML header
with no luck. Any other ideas? In the meantime, I will continue looking.. 

-----Original Message-----
From: mfncooper@gmail.com [mailto:mfncooper@gmail.com] On Behalf Of Martin Cooper
Sent: Tuesday, February 07, 2006 1:59 PM
To: Jakarta Commons Users List
Subject: Re: Help with JSP parsing form data for UTF-8 charsets?

It looks like you forgot to tell the browser. Try adding:

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

--
Martin Cooper


On 2/7/06, Michael Atlas <MAtlas@basistech.com> wrote:
>
> Hello,
>
> I am trying to update a MySQL database record with UTF-8 characters 
> with my JSP application. I am using FileUpload to process multipart 
> form data that may also contain UTF-8 characters.
>
> 1) I have MySQL correctly configured to handle UTF8 and have tested 
> insert/update/select with UTF8 characters
>
> 2) I have an "editRecord.jsp" page. At the top of the page, I specify:
>
> <% request.setCharacterEncoding("UTF-8"); %>
>
> 3) I have an input form which is specified in that page which follows:
> <form action="<c:url value="/updateRecord.jsp"/>"
> name="updatetForm" method="post"
> ACCEPT-CHARSET="UTF-8"
> enctype="multipart/form-data">
>
> 4) I have a servlet filter that takes every HttpServletRequest and 
> modifies that object in doFilter(...){ ...
> request.setCharacterEncoding("UTF-8");
> chain.doFilter(...)
> }
>
> 5) In updateRecord.jsp, I fill a JavaBean with the form data. Here's 
> an example of the form input:
>
> name = Company
> Comments=Here's some unicode text: "(chinese text) test"
>
> I see:
> name = Company
> Comments=Here's some unicode text: "خار..test"
>
> 6) In my JSP updateBean I am using the FileUpload class:
> FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload 
> upload = new ServletFileUpload(factory); 
> upload.setHeaderEncoding("UTF-8");
> ....
>
> 7) When I put a breakpoint and inspect the contents of the "comments" 
> form item after posting the form, I see
>
> Here's some unicode text: "خار....test"
>
> Where could I possibly be missing something to force UTF8 encoding of 
> these values?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message