java.io.CharConversionException: Not an ISO 8859-1

Servlet不能正常显示中文:        

                                String outStr = null;

        if (str == null) {

            outStr = ” 请输入关键字!”;

        

        } else {

            outStr = str;

        }

        res.setContentType(“text/html;charset=gb2312″);

        ServletOutputStream out = res.getOutputStream();

        out.println(““);

        out.println(““);

        out.println(““);

        out.println(outStr);

        out.println(““);

        out.println(““);

    

java.io.CharConversionException: Not an ISO 8859-1 character: 请

    javax.servlet.ServletOutputStream.print(ServletOutputStream.java:89)

    javax.servlet.ServletOutputStream.println(ServletOutputStream.java:242)

    dataBase.searchArticle.doGet(searchArticle.java:34)

    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

    javax.servlet.http.HttpServlet.service(HttpServlet.java:717

浏览是发生错误:



ServletOutputStream out = res.getOutputStream();

改为:

PrintWriter out = res.getWriter();

就可以了。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>