我们都知道,get请求和post请求的一个比较显著区别就是,在使用post请求的时候,中文不会乱码,但是在使用get请求的时候,如果url后面带有中文就会乱码了 。那么这个怎么解决呢?
文章插图
前提:配置项目的encoding编码位utf-8的前提下 。如,使用spring项目的时候,可以在spring的配置文件中添加如下的:
<filter>
<filter-name>encoding</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>encoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
两个方案:
一:使用Tomcat,将项目直接部署到tomcat中的
这种情况下,如果想要修改get请求中文参数不乱码的话,需要修改:
在tomcat的配置文件中添加如下配置:
<!-- 添加属性URIEncoding="utf-8"可以解决get乱码问题,然后重启服务器-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8" />
二:如果使用的是maven 插件运行tomcat的话,就需要在pom.xml的maven插件中配置编码方式:
<plugins>
<!-- maven项目的热部署使用的插件 使用tomcat7的插件的话,运行时设置部署命令是需要使用tomcat7:deploy -->
<plugin>
<groupId>org.Apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<uriEncoding>UTF-8</uriEncoding> <!--配置编码方式为UTF-8-->
<url>http://localhost:8080/manager/text</url>
<path>/</path>
<server>tomcat</server>
<username>tomcat</username>
<password>123456</password>
</configuration>
</plugin>
【怎么设置tomcat在get请求的中文也不乱码?两种情况下配置】
推荐阅读
- 请问枕头套不要了能扔吗 枕头套又黄又黑怎么清洗
- 企业感染恶意软件该怎么处理
- Tomcat结构原理详解
- 白天睡觉魇住是屋里不干净 梦魇其实就是有鬼怎么办
- 窗户贴膜时间长了会撕不下来吗,窗户贴膜撕不下来怎么办
- 透明软门帘是什么材质,透明软门帘怎么擦更亮
- 空调消毒怎么操作,用什么给空调过滤网消毒
- 吊扇嘎吱嘎吱响怎么办,吊扇嘎吱嘎吱的响会突然的掉吗
- 九阳豆浆机显示e19是怎么回事,豆浆机温度过高停止打豆浆怎么办
- 天然真石漆能不能用于室内,天然真石漆怎么使用