Jun 29th, 2009, 02:29 AM
UTF-8 encoding - resolved
When you build UTF-8 project, there are many small things that you have to care about. I workd on a project that needs to take care of UTF-8 for all countries encoding. It wasn't always easy to find solutions for all cornor cases. Below is a list of things you need to worry about if you are working on UTF-8 encoding project. If you can't find solutions from the list to handle your specific use case, you can post here or email me firstname.lastname@example.org. I may omit some cornor cases or, it maybe something new. Either case, I am interested in make this list full.
1. Your jsp:
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
2. Your html:
<meta http-equiv="content-type" content="text/html; charset=UTF-8" http-equiv="language" />
3. Your java code:
4. tomcat server.xml setting: <Connector port="8080" maxHttpHeaderSize="8192" URIEncoding="UTF-8"...../>
5. If you are using spring frame work, set the following in web.xml, it handles POST requests
6. If you are using spring frame work, set the following in your project-servlet.xml. This will take care of file uploading.
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.C ommonsMultipartResolver"
7. If your are getting url appending utf-8 params, you need to do the following.
byte file = fileValue.getBytes("UTF-8"); //toString later.
8. If you are reading from file system in stream
new FileInputStream(fullFileName), "UTF-8");
If you are reading from file system in String
String myFileString = new String(stringFromFileSystem.getBytes(), "UTF-8");
9. If you are writting to file system
new FileOutputStream(fullFilePath), "UTF-8");
10. If you get a bug saying user prompt window can't recognize local encoding, the only answer for this one is:
The user needs to turn their IE/encoding/local encoding on. E.g. encoding/Chinse simplified
11. If you are doing your junit test and needs to write unicode in your IDE, you need to config this in your IED, suppose it is eclipse:
Last edited by touchsky88; Jun 29th, 2009 at 02:37 AM.