方法一:
// 获取请求参数 String username = req.getParameter("username"); //1 先以 iso8859-1 进行编码 //2 再以 utf-8 进行解码 username = new String(username.getBytes("iso-8859-1"), "UTF-8");
方法二:
// 设置请求体的字符集为 UTF-8 ,从而解决 post 请求的中文乱码问题 req.setCharacterEncoding("UTF-8"); System.out.println("-------------doPost------------"); // 获取请求参数 String username = req.getParameter("username"); String password = req.getParameter("password"); String[] hobby = req.getParameterValues("hobby"); System.out.println("用户名:" + username); System.out.println("密码:" + password); System.out.println("兴趣爱好:" + Arrays.asList(hobby));