ssm的web项目,浏览器使用get链接传递的为中文参数时,出现乱码
做搜索功能时,搜索手机,那么浏览器传递的参数为中文参数“手机”,但传递的默认编码格式为iso-8859-1,所以传到后台时,是乱码。
此时,有两种解决方法:
(1)修改tomcat的配置文件;
(2)(如果使用的是tomcat插件,无配置文件)后台在接收参数后,直接将其编码格式转换为中文编码utf-8格式。
keyword = new String(keyword.getBytes("iso-8859-1"),"utf-8");
显示乱码,未搜索到结果
显示正常,能够实现搜索功能