解決後臺接受前臺中文資訊亂碼的問題
阿新 • • 發佈:2019-02-07
按照這四個步驟進行修復:
並且
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
<filter>
<filter-name>setEncoding</filter-name>
<filter-class>com.dinner.filter.CharsetFilters</filter-class>
<init-param>
<param-name>coding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>/*</url-pattern>
開發中發現Windows版Eclipse預設Java和Web工程的預設編碼方式不那麼遂人願,修改方法如下:
1. Web工程檔案編碼修改方式
Window -> Preference -> Content types
推薦將Web相關檔案的編碼都設定為UTF-8
2. Java原始檔編碼修改方式
Window -> Preference -> Workspace -> Text file encoding
首先:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>並且
request.setCharacterEncoding("gb2312");
第二:
配置 server.xml。<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
第三:
配置 web.xml<filter>
<filter-name>setEncoding</filter-name>
<filter-class>com.dinner.filter.CharsetFilters</filter-class>
<init-param>
<param-name>coding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
第四:
工程編碼開發中發現Windows版Eclipse預設Java和Web工程的預設編碼方式不那麼遂人願,修改方法如下:
1. Web工程檔案編碼修改方式
Window -> Preference -> Content types
推薦將Web相關檔案的編碼都設定為UTF-8
2. Java原始檔編碼修改方式
Window -> Preference -> Workspace -> Text file encoding
Windows平臺預設為GBK,Linux平臺預設為UTF-8
原文地址:http://bbs.csdn.net/topics/390372335/