HttpServletRequest的.getParameter方法不支持解析中文,导致解析后乱码
文章目录
问题提出
后端需要接收前端发送的中文字符串,HttpServletRequest的.getParameter方法不支持解析中文,导致解析后乱码。
问题解决
使用String类的构造方法,进行转码,例如:
String productName = request.getParameter("productName");
productName = new String(productName.getBytes("8859_1"), "utf8"); // 接收中文,转码


评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论