Java Web开发中文乱码总结

四、其他

在jsp中的页面使用response.setContentType()等设置字符集会破坏jsp容器自身的页面编码,会引起html中字符乱码,脚本不会乱,所以不建议设置。在开发中多采用page指令设置字符集。

<!DOCTYPE html PUBLIC> <html> <head>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">     <title>Insert title here</title> </head> <body>     <%         response.setContentType("text/html;charset=UTF-8");         String str = new String("你好".getBytes("iso-8859-1"), "utf-8");     %>     <p>你好</p>     <br><%=str%> </body> </html>