作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
Tomcat 未正确编码包含 unicode 字符的字符串文字。问题出现在 Linux 服务器上,但不出现在我的开发机器 (Windows) 上。它仅影响字符串文字(不影响从数据库或文件中读取的字符串!!!)。
URIEncoding="utf-8"
。以上均无效。关于我可能遗漏的任何想法?
public class Test extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/plain;");
Writer w = resp.getWriter();
w.write("Μαλακία Latin"); //Some unicode characters
w.close();
}
上面在浏览器中显示了这一点。 γγγ»γδεγε拉丁语
最佳答案
您可以在编译时传入-encoding 'utf-8' 或-encoding 'iso-8859-1' 来在javac 读取文件时强制对文件进行编码。只要确保它与您的 .java 文件实际编码的任何编码相匹配即可。
http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
-encoding encoding Set the source file encoding name, such as EUC-JP and UTF-8. If -encoding is not specified, the platform default converter is used.
关于java - 如何在tomcat中使用UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9822663/
我是一名优秀的程序员,十分优秀!