Java学习笔记·Servlet parameter参数传递utf-8文字编码正常显示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/syjsxxjy/article/details/50448011

传递parameter时,正常显示各种语言文字的编码

首先设置tomcat的uriencoding为iso-8859-1(tomcat配置文件里的server.xml)

<Connector URIEncoding="iso-8859-1" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

Servlet参数传递代码实现:

String tmp=request.getParameter("cars");
String carname=new String (tmp.getBytes("iso-8859-1"),"utf-8");

参考来自:http://stackoverflow.com/questions/3029401/java-servlet-and-utf-8-problem

猜你喜欢

转载自blog.csdn.net/syjsxxjy/article/details/50448011