`

spring mvc rest风格的URL输入中文乱码问题

 
阅读更多

 

<!-- 处理请求时返回json字符串的中文乱码问题 -->
	<mvc:annotation-driven>
		<mvc:message-converters>
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>text/html;charset=UTF-8</value>
					</list>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>

 

tomcat 的 server.xml中,加入URIEncoding="UTF-8"

<Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

 

当然,也可以在代码里转

new String(s1.getBytes("ISO-8859-1"), "UTF-8");

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics