tomcat设置post和get都支持中文参数

jsp的指令这里就不说了

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    //单设置setCharacterEncoding为utf8 只能正常显示post参数
    request.setCharacterEncoding("utf-8");
    response.getWriter().write(request.getParameter("name"));

如果需要get接收中文参数 需要设置 tomcat的配置文件

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingURI="true" />

增加的属性
设置URI的编码和网页的编码相同

useBodyEncodingURI="true"

另外测试结果,eclipse内置浏览器接收中文get参数还是报异常
但是谷歌和火狐浏览器打开没有问题 可以正常显示参数

注意 在tomcat的安装目录的server.xml需要配置
在eclipse的tomcat映射里server.xml也需要配置

猜你喜欢

转载自blog.csdn.net/qq_27617675/article/details/82564230
今日推荐