看板 java 關於我們 聯絡資訊
哈囉 各位業界先進好 小弟不才有個問題請教 目前正在開發以SpringMVC + Mybatis 的restful webservice api (APP後端) 不過遇到了一個問題 就是在做Http post時,Response的中文會有亂碼的問題(get卻正常) 不過小弟的情況比較特殊 若WEB啟動於eclipse的Tomcat, 則無回應中文亂碼問題 但部署在獨立的Tomcat下, 才會出現在中文亂碼問題.. Ex. eclipse tomcat test回應中文正常 http://imgur.com/a/tQNRq Ex. 獨立Tomcat佈署 回應中文亂碼 http://imgur.com/a/KQIKq 小弟GOOGLE做了以下設置均無效 1. RequestMapping(...., produce="application/json;charset=UTF-8") http://imgur.com/a/0FPsK 2. web.xml編碼設定 ... <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> .. 3. spring-mvc.xml設定 http://imgur.com/a/0FPsK ... 另外有參考估狗試過許多設定了, 只是未做紀錄, 但都不WORK 因此我在懷疑會不會是Tomcat的編碼問題 目前只有嚐試在catalina.bat加入 set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG% "-Dfile.encoding=UTF-8" 不過仍然無法, 想請問是否有人遇過相同問題 如果eclipse亂碼而stanalone tomcat正常我還覺得還好.. 但到時候開發完成一定是直接佈署在tomcat上啊... 再請各位有經驗的大大指點迷津 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.138.56.120 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1487213722.A.DC4.html
gpctv: 要不要試試在tomcat 的 server.xml加上 02/16 17:08
gpctv: <Connector .......加 URIEncoding="UTF-8"> 02/16 17:08
PttJesus: 有試過了 不過此法好像僅適用於get 02/17 10:00
ssccg: 你的controller method是怎麼寫的? 02/17 10:18
PttJesus: http://imgur.com/a/YNXRi 02/18 14:26