j2ee笔记
request中文乱码问题
- get:tomcat7及以下版本,get方式获取参数会乱码,
- post:都会乱码
因为java默认编码
ISO-8859-1
不支持中文
解决
仅针对post
1 | request.setCharacterEncoding("utf-8"); |
针对get,慎用,仅针对会乱码的情况(如果原来不乱,用之后会乱)
1 | new String(request.getParameter("name").getBytes("ISO-8859_1"),"utf-8"); |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.