Tomcat / Linux上的UTF-8和Servlet [英] UTF-8 and Servlets on Tomcat/Linux

查看:142
本文介绍了Tomcat / Linux上的UTF-8和Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Tomcat 6 / Linux上从Servlet读写UTF-8时遇到了一些问题。请求和响应是utf-8,浏览器是utf-8,在连接器和主机上的server.xml中设置了URIEncoding。简而言之,每个已知的东西对我来说都是代码本身,服务器配置是utf-8。

I've had some problems with reading and writing UTF-8 from servlets on Tomcat 6 / Linux. request and response were utf-8, browser was utf-8, URIEncoding was set in server.xml on both connectors and hosts. Ins short, every known thing for me in code itself, and server configuration was utf-8.

当读取请求时,我不得不从String取字节数组,然后再将该字节数组转换为String。当写请求时,我不得不写字节,而不是字符串本身,以获得正确的响应(否则我会得到一个异常,表示一些非ASCII字符无效ISO 8859-1)。

When reading request, I've had to take byte array from String, and then convert that byte array into String again. When writing request I've had to write bytes, not String itself, in order to get proper response (otherwise I would get an exception that says some non ASCII character is not valid ISO 8859-1).

推荐答案

更改LANG环境变量是解决问题的一种方法。

Changing the LANG environment variable is one way to solve the problem.

正式的方法是将字符编码设置为sevlet过滤器: http://wiki.apache.org/ tomcat / Tomcat / UTF-8

The official way is to set the character encoding in a sevlet filter: http://wiki.apache.org/tomcat/Tomcat/UTF-8

一些背景信息: http://www.crazysquirrel.com/computing/general/form-encoding.jspx

这篇关于Tomcat / Linux上的UTF-8和Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆