The problem that I was facing was something like this. I was using Apache Commons File Upload library to upload and download some file.
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:
in the Servlet:
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!
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!
Comments
http://chaptersfrommylife.blogspot.com/2010/04/april-2010-youngistaan-ka-wow-contest.html
to help my chances in the pepsi contest. Thank you
The only good solution that I find on internet.
Thank you
Thanks
Javin
Why String is immutable in Java
FIX Protocol tutorial
Please post more details about the solution in StackOverFlow.
Thanks,
Ramanathan