Mom is not worried about my coding problem any more. Chinese code Fusion, windows,django,python,java,html

Source: Internet
Author: User
Tags locale

Write a small web app with Django. A business-related jar package called in the application and displays the return value of the jar package. It is in the Windows environment, using the Django framework, the Python language to call the Java jar package, output content into, HTML. involves a bunch of coding problems.
the process is not garbled, is garbled. Finally in the expert guidance under the fix. Hereby record. mom is not worried about my coding problem any more.
1. python file header, which represents the encoding format used by the contents of the file #-*-Coding:utf-8-*-
2. The encoding format of the Python sys. Reload (SYS)
Sys.setdefaultencoding ("UTF8") 3.  Locale.getpreferredencoding () 4.    Python can print out the encoding format for standard input and standard output. Print sys.getdefaultencoding ()
Print locale.getpreferredencoding ()
Print sys.stdin.encoding
Print sys.stdout.encoding
5 python encode encodes a string into a 16 binary number. Decode decoding into Chinese msg = "Liu This is a stream." Volume calibration SMS, in order for him to grow a bit? ABCDEFG this. Why? "
Print msg msg.encode (' utf-8 ') cmd = "Java-dfile.encoding=utf-8-jar jar/netflowcorrect-0.1-jar-with-dependencies.ja R%s "% Msg.encode (' GBK ')
Print Cmd.decode (' GBK '). Encode (' UTF8 ')
6 The Window Environment command line uses GBK encoding by default. Using UTF8 to encode the parameters will be decoded by the system to GBK, garbled (may only be a small part), but also garbled. Most of the time is used to confirm the matter.
7 Java commands can specify the default character encoding Java-dfile.encoding=utf-8-jar jar/netflowcorrect-0.1-jar-with-dependencies.jar8 print character encoding in Java         SYSTEM.OUT.PRINTLN ("Default charset=" + charset.defaultcharset ());        System.setproperty ("file.encoding", "Latin-1");        SYSTEM.OUT.PRINTLN ("file.encoding= "+ System.getproperty (" file.encoding "));        System.out.println (" Default charset= "+ Charset.defaultcharset ());        System.out.println ("Default Charset in use=" + getdefaultcharset ( ));    private static String Getdefaultcharset () {        OutputStreamWriter writer = new Ou Tputstreamwriter (New Bytearrayoutputstream ());        String enc = writer.getencoding ();        return enc;   }9 in Java string   encoding conversion               & nbsp Log ("Input 2:" +new String (Args[index].getbytes ("GBK"), "GBK")); &nbsP               log ("Input 3:" +new String (Args[index].getbytes ("Utf-8"), "GBK"));  & nbsp             log ("Input 4:" +new String (Args[index].getbytes ("GB2312"), "GBK"));    & nbsp           log ("Input 5:" +new String (Args[index].getbytes ("cp936"), "GBK"));      & nbsp         log ("Input 6:" +new String (Args[index].getbytes ("iso-8859-1"), "GBK")), System.out specified encoding in Java
private static void log (String msg) {try {printstream out = new PrintStream (System.out, True, "UTF-8")            ;        OUT.PRINTLN (msg);        } catch (Unsupportedencodingexception e) {e.printstacktrace (); }    }
Each HTML file specifies the encoding <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

Mom is not worried about my coding problem any more. Chinese code Fusion, windows,django,python,java,html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.