2009年2月19日 星期四

tomcat6 servlet透過get傳送utf-8中文表單資料

根據文件 tomcat6/webapps/docs/config/http.html 內的說法,
tomcat預設的URIEncoding是ISO-8859-1,
所以如果表單method="get",又含有中文的資料的話,那麼傳遞參數後會出現值變成亂碼的情形;
就算在servlet內設定了request.setCharacterEncoding("utf-8")也是沒有用。

修正的方法:

sudo gedit /usr/share/tomcat6/conf/server.xml
在裡面找到的元素
在中間加上URIEncoding="utf-8"的屬性就可以了:


http://overinfinityresearch.blogspot.com/2007/10/tomcat6-servletget.html

沒有留言:

張貼留言