SERVLET + TOMCAT Chinese garbled principle and solution

xiaoxiao2021-03-06  41

SERVLET TOMCAT Chinese garbled: Because Java's .class file uses Unicode encoding, and Windows 2000 operating system and browser uses GBK (GB2312 encoded extension) encoding, so it is necessary to specify the view. The encoding format of the unit. For more detailed description, see http://blog.9cbs.net/abnerchai/archive/2004/04/28/javacnproblemup.aspx servlet Tomcat Chinese garbled solution a) Change C: /javasoft/tomcat5.5/ Conf / server.xml, specifying the code format of the browser is "Simplified Chinese": Method is to find tag, bold word is what I added. You can verify that your changes are successful: Before you change, you will click on the menu "View | Encoding" in your menu, you will find "Western" (ISO) "is selected. After the changes, click on the menu "View | Encoding", "Simplified Chinese (GB2312) will be found in the selected state. b) further the Java program, this is my program: public class ThreeParams extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType ( "text / html; charset = GBK"); ...}} Bolds must be needed, and its role is to let the browser convert Unicode characters to GBK characters. This page's content and browser's display mode is set to GBK, and it will not be garbled.

If it is a JSP page, the equivalent to the above is: <% @ page contenttype = "text / html; charset = GBK"%>

转载请注明原文地址:https://www.9cbs.com/read-64724.html

New Post(0)