问题描述
spring mvc 程序,所有java源码强制为utf8,jsp以<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">强制为utf8jetty上,post的中文可以直接读取(采用@RequestParam方式,servlet的request.get 也可以读)get的中文参数读取在ie乱码,后在ie中使用js的encodeURI(encodeURI(url))解决。war包直接移植到tomcat后,post,get皆读取中文乱码,使用 org.springframework.web.filter.CharacterEncodingFilter 可以解决post乱码现在就是无法解决tomcat的 get乱码问题。
解决方案
这种情况可以考虑在容器(tomcat)上做配置在$TOMCAT_HOME/conf下的server.xml中做如下配置:<Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8" />
解决方案二:
修改Tomcat目录/conf下的server.xml,找到类似如下行, <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" />改为: <Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>或者<Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" />