Servlet - 请求数据中文乱码问题

1. 使用String进数据重新编码

  String username = request.getParameter("username");

  username = new String(username.getBytes("iso8859-1"), "utf-8");

2. 使用公共配置

  GET方式提交:

    1. 在Tomcat的conf目录中修改server.xml文件, 在Connector标签中增加属性 useBodyEncodingForURI="true"

    2. request.setCharacterEncoding("utf-8");

  POST方式提交: 

    直接加 request.setCharacterEncoding("utf-8");

猜你喜欢

转载自www.cnblogs.com/mpci/p/12613846.html
今日推荐