HttpServletResponse.getOutputStream().print(rspJson.toString());如是中文则报:
java.io.CharConversionException: Not an ISO 8859-1 character:
javax.servlet.ServletOutputStream.print(ServletOutputStream.java:77)
javax.servlet.ServletOutputStream.println(ServletOutputStream.java:187)
com.diyou.server.dispatch.FrontDispatch.service(FrontDispatch.java:67)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
方案:
ServletOutputStream out = res.getOutputStream();
OutputStreamWriter ow = new OutputStreamWriter(out,"utf-8");
或
PrintWriter pw = response.getWriter();
均可输出中文。HttpServletResponse.getOutputStream()默认编码中文
项目编码统一设置成GBK或UTF-8无影响,只要统一就行。
GBK的好处在于编译成JAVADOC时的优势。
java.io.CharConversionException: Not an ISO 8859-1 character:
javax.servlet.ServletOutputStream.print(ServletOutputStream.java:77)
javax.servlet.ServletOutputStream.println(ServletOutputStream.java:187)
com.diyou.server.dispatch.FrontDispatch.service(FrontDispatch.java:67)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
方案:
ServletOutputStream out = res.getOutputStream();
OutputStreamWriter ow = new OutputStreamWriter(out,"utf-8");
或
PrintWriter pw = response.getWriter();
均可输出中文。HttpServletResponse.getOutputStream()默认编码中文
项目编码统一设置成GBK或UTF-8无影响,只要统一就行。
GBK的好处在于编译成JAVADOC时的优势。