How to get UTF-8 in Node.js?

Hook into you response generator or create a middleware that does the following: res.setHeader(“Content-Type”, “application/json; charset=utf-8”); Otherwise the browser displays the content in it’s favorite encoding. If this doesn’t help you DB is probably in the wrong encoding. For older node.js versions use: res.header(“Content-Type”, “application/json; charset=utf-8”);

Why do cookie values with whitespace arrive at the client side with quotes?

When you set a cookie value with one of the following values as mentioned in Cookie#setValue(), With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons. Empty values may not behave the same way on all browsers. then the average … Read more

UTF-8 Encoding name in downloaded file

I got it solved as the following. fileName = dateString+”_マイページ情報.xls”; fileName = URLEncoder.encode(fileName,”UTF-8″); try { response.setContentType(“application/ms-excel; charset=UTF-8”); response.setCharacterEncoding(“UTF-8”); if(browserType.equals(“IE”)||browserType.equals(“Chrome”)) response.setHeader(“Content-Disposition”,”attachment; filename=”+fileName); if(browserType.endsWith(“Firefox”)) response.setHeader(“Content-Disposition”,”attachment; filename*=UTF-8””+fileName); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); }

reading text file with utf-8 encoding using java

Use import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class test { public static void main(String[] args){ try { File fileDir = new File(“PATH_TO_FILE”); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(fileDir), “UTF-8”)); String str; while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); } catch (UnsupportedEncodingException e) { … Read more

invalid byte 2 of 2-byte UTF-8 sequence

Most commonly it’s due to feeding ISO-8859-x (Latin-x, like Latin-1) but parser thinking it is getting UTF-8. Certain sequences of Latin-1 characters (two consecutive characters with accents or umlauts) form something that is invalid as UTF-8, and specifically such that based on first byte, second byte has unexpected high-order bits. This can easily occur when … Read more