记住一点:
你以什么方式或者编码写的数据就要告诉浏览器以什么方式或者码表打开,否则会出现乱码。
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- test(response);
- }
-
- public void test(HttpServletResponse response) throws UnsupportedEncodingException, IOException{
- response.setHeader("Content-type","text/html;charset=UTF-8"); //指定消息头以UTF-8码表读数据
- String data="中国";
- response.getOutputStream().write(data.getBytes("utf-8"));
- }
阅读(3637) | 评论(0) | 转发(0) |