Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UTF-8 encoding not honored when form has multipart/form-data

 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form in which user can upload a file and another field 'name' in which she can give any name to the file being loaded. (Please see the image in attachements) When I submit the form, the file is uploaded fine but the value in name field is messed up. I have followed all the possible suggestions I found:

1) <%@page pageEncoding="UTF-8"%> set.
2) <%@page contentType="text/html;charset=UTF-8"%> set after the first directive.
3) <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> in the head.
4) enctype="multipart/form-data" attribute in the form.
5) accept-charset="UTF-8" attribute in the form.

in the Servlet:
1) before doing any operations on request object: request.setCharacterEncoding("UTF-8");

2) Getting the value:

On the UI, I can see the characters properly but when the value is being passed to java strings, all hell breaks loose!

But nothing seems to be working.

This issue is coming in this form only where enctype is multipart/form-data. Rest everywhere having just 1) and 2) work fine.
Can someone please give some ideas what can be going wrong?

Thanks
Abhishek
img.PNG
Snapshot of the form
[Thumbnail for img.PNG]
 
Joachim Rohde
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which servlet container are you using?
Just in case you are using Tomcat, try to set the URIEncoding of your connector in server.xml to UTF-8 (see also: http://wiki.apache.org/tomcat/Tomcat/UTF-8)

Another shot into the dark: have you tried to pass getBytes() your encoding explicitly?

Anyway: good luck!
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I tried passing encoding explicitly, but that doesn't work either. I am using Weblogic server. Can we set encoding for weblogic also?

Please Please Please guys, this is very critical for me. Please help!

Thanks
Abhishek
 
Paul Clapham
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the purpose of the tricky code in line 6? You've told everything in sight to use UTF-8, then you don't trust that, so you start using random encodings instead? Try this instead:
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I first tried using just

when that didn't work, I used


 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, this is the solution:
Instead of

or


do :
 
carl norburn
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I kiss you Abhishek! I was stuck with the multipart/form-data utf8 problem for hours!

item.getString("UTF-8").trim()

works a treat

Thanks
 
Sendhil Kumar S
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@carl norburn Am still getting the same error.? May i have the full code please.! Am stuck with this for days..??
 
Sendhil Kumar S
Greenhorn
Posts: 5
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya..got the output...Thanks for the support..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic