Tomcat URL乱码
程序员文章站
2022-07-14 12:46:08
...
我们在开发REST服务的时候,尤其是做中文项目的时候,会遇到传入参数乱码的问题,这个就比较麻烦了,因为原因真的很复杂,根本不止我所列的两个地方,还得具体问题具体分析了。
如果你用的是Spring MVC,首先要检查一下CharacterEncodingFilter是否配置了编码
然后再看一下Tomcat的server.xml是否配置了编码
http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html#Common_Attributes
然后就好用了哦~
如果你用的是Spring MVC,首先要检查一下CharacterEncodingFilter是否配置了编码
<filter> <filter-name>encodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
然后再看一下Tomcat的server.xml是否配置了编码
http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html#Common_Attributes
<!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
然后就好用了哦~
上一篇: SCJP 认证考试指南
下一篇: 让读书成为一种习惯
推荐阅读
-
Caused by SSLError("Can’t connect to HTTPS URL because the SSL module is not available)
-
英文Windows系统打开带中文TXT出现乱码
-
从SpringBoot构建十万博文聊聊Tomcat集群监控
-
Django-URL路由系统
-
Nginx下配置pathinfo及ThinkPHP的URL Rewrite模式支持
-
访问网站提示An error occurred on the server when processing the URL的解决方法
-
Nginx下支持Thinkphp URL Rewrite的配置示例
-
Ubuntu下Nginx配置ThinkPHP的Pathinfo和URl Rewrite模式
-
WordPress在window2003 IIS ISAPI ReWrite下的URL规则
-
在MyEclipse中配置Tomcat服务器7.0图文教程