Encoding and Servlet API: setContentType or setCharacterEncoding

The javadoc is pretty clear about the difference: void setCharacterEncoding(String charset) Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by setContentType(java.lang.String) or setLocale(java.util.Locale), this method overrides it. Calling setContentType(java.lang.String) with the String of text/html and calling this … Read more

How to download any(!) webpage with correct charset in python?

When you download a file with urllib or urllib2, you can find out whether a charset header was transmitted: fp = urllib2.urlopen(request) charset = fp.headers.getparam(‘charset’) You can use BeautifulSoup to locate a meta element in the HTML: soup = BeatifulSoup.BeautifulSoup(data) meta = soup.findAll(‘meta’, {‘http-equiv’:lambda v:v.lower()==’content-type’}) If neither is available, browsers typically fall back to user … Read more

How does UTF-8 encoding identify single byte and double byte characters?

For example, “Aݔ” is stored as “410754” That’s not how UTF-8 works. Characters U+0000 through U+007F (aka ASCII) are stored as single bytes. They are the only characters whose codepoints numerically match their UTF-8 presentation. For example, U+0041 becomes 0x41 which is 01000001 in binary. All other characters are represented with multiple bytes. U+0080 through … Read more

HTML5: which is better – using a character entity vs using a character directly?

If the encoding is UTF-8, the normal characters will work fine, and there is no reason not to use them. Browsers that don’t support UTF-8 will have lots of other issues while displaying a modern webpage, so don’t worry about that. So it is easier and more readable to use the characters and I would … Read more

How do I use MultiByteToWideChar?

You must call MultiByteToWideChar twice: The first call to MultiByteToWideChar is used to find the buffer size you need for the wide string. Look at Microsoft’s documentation; it states: If the function succeeds and cchWideChar is 0, the return value is the required size, in characters, for the buffer indicated by lpWideCharStr. Thus, to make … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)