• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for img.PNG]
Snapshot of the form
 
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 28326
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, this is the solution:
Instead of

or


do :
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya..got the output...Thanks for the support..
 
This tiny ad is guaranteed to be gluten free.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic