2014年6月11日 星期三

[Tomcat] 解決GET QueryString中文亂碼問題

問題:
輸入URL,ex:http://localhost:8080/xxx_servlet?name=業務小張, 於doGet() 中 request.getParameter("name") , 取到的值是亂碼, 但用Post Method 方式卻不會發生中文亂碼。

原因:
Tomcat 對於get method submit的請求,針對query string 採用和post method不同的處理方式 
request.setCharacterEncoding("big5") 只對post method有效,但對get method不起作用。

解決方式:
修改Tomcat的server.xml, 找到connector connectiontimeout="20000" port="8080" protocol="HTTP/1.1" redirectport="8443" 這行,加入URIEncoding="big5" 屬性, 重新啟動Tomcat Server, 即可以解決此問題

沒有留言:

張貼留言