I had 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.
When I submitted the form, the file was uploaded fine but the value in name field was garbled. I followed all the possible suggestions I found:
- <%@page pageEncoding="UTF-8"%> set.
- <%@page contentType="text/html;charset=UTF-8"%gt; set after the first directive.
- <meta equiv="Content-Type" content="text/html;charset=UTF-8"> in the head.
- enctype="multipart/form-data" attribute in the form.
- accept-charset="UTF-8" attribute in the form.
in the Servlet:
- before doing any operations on request object: request.setCharacterEncoding("UTF-8");
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
//For regular form field:
name = item.getFieldName();
//converting from default encoding to UTF-8.
value = new String(item.getString().getBytes(), "UTF-8");
}
But this too didn't work. Finally after lot of trial and error methods, this is the call which set everything right.
value = item.getString("UTF-8").trim();
I was able to get the value in text field correct, ungarbled!
3 comments:
Thanks for visiting my blog ... I am glad you liked my post. If possible leave a comment on
http://chaptersfrommylife.blogspot.com/2010/04/april-2010-youngistaan-ka-wow-contest.html
to help my chances in the pepsi contest. Thank you
like like like like
The only good solution that I find on internet.
Thank you
Good work man keep it up.
Thanks
Javin
Why String is immutable in Java
FIX Protocol tutorial
Post a Comment