SpringMVC-解決post提交中文亂碼和get中文亂碼問題(post-過濾器get-重新編碼)

問題:中文亂碼問題

    1、post亂碼

<!-- 解決post亂碼問題 -->
	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>utf-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
    2、get亂碼問題
1、在tomcat的conf的server.xml中配置
	<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
	2、使用方法對參數重新編碼
	String userName new 
	String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")
	ISO8859-1是tomcat默認編碼,需要將tomcat編碼後的內容按utf-8編碼


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章