3. servlet解决乱码

# doPost方法中解决乱码

## request.setCharacterEncoding("UTF-8");

## 必须在所有获取数据的动作之前设置

# doGet方法中解决乱码

## tomcat8及之后,不用设置编码

## tomcat8之前:比如String name = request.getParameter("name"),name是乱码,则:

## byte[] bytes = name.getBytes("ISO-8859-1");

## name = new String(bytes, "UTF-8");

posted on 2022-11-16 22:44  大聪明QAQ  阅读(13)  评论(0)    收藏  举报