I am using PrintWriter
as follows to get the output in the browser:Using PrintWriter, I am getting Chinese junk characters in browser
PrintWriter pw = response.getwriter();
StringBuffer sb = getTextFromDatabase();
pw.print(sb);
However, this prints the following Chinese junk characters:
格㸳潃浭湥獴⼼㍨‾瓊扡敬㰾牴戠捧汯牯✽䔣䔷䔷❆㰾摴傾獯整湏›〱㈭ⴷ〲〱ㄠ㨴㌰㔺祂›教桳慷瑮丠祡歡⠊湹祡歡捀獩潣挮浯硅散汬湥㱴琯㹤⼼牴㰾牴戠捧汯牯✽䔣䔷䔷❆㰾摴㰾琯㹤⼼牴㰾牴戠捧汯牯✽䔣䔷䔷❆㰾摴傾獯整湏›〱㈭ⴷ〲〱ㄠ㨴㐰ㄺ祂›教桳慷瑮丠祡歡⠊湹祡歡捀獩潣挮浯敶祲朠潯㱤琯㹤⼼牴㰾牴戠捧汯牯✽䔣䔷䔷❆㰾摴㰾琯㹤⼼牴㰾牴戠捧汯牯✽䔣䔷䔷❆㰾摴傾獯整湏›〱㈭ⴷ〲〱ㄠ㨴㜱㌺ਸ਼祂›教桳慷瑮丠祡歡⠊湹祡歡捀獩潣挮浯桔獩槧瀦琠獥㱴琯㹤⼼牴㰾琯扡敬㰾牢⼠‾格㸳潐瑳夠畯潃浭湥㱴栯㸳㰠潦浲慍瑣潩㵮䌢浯敭瑮即牥汶瑥•敭桴摯∽敧≴渠浡㵥撟浯敭瑮瀠浲•湯畳浢瑩∽爠瑥牽慖楬慤整瀠浲⤨∻‾瓊扡敬†眠摩桴∽〳 ∰栠楥檜㵴㌢〰㸢ठ瓊㹲瓊㹤氼扡汥映牯∽慮敭㸢潃浭湥㩴猼慰汣獡㵳洢湡呤汃獡≳⨾⼼灳湡㰾氯扡汥㰾牢㸯瓊硥懾敲慮敭∽潣瑮湥≴槧㵤撟浯敭瑮硔䅴敲≡撓慬獳∽整璸牡慥氠牡敧•潣獬∽㠲•潲獷∽∶㸠⼼整璸牡慥㰾琯㹤⼼牴㰾牴㰾摴㰾慬敢潦㵲渢浡≥舉浡㩥猼慰汣獡㵳洢湡呤汃獡≳⨾灳湡㰾氯扡汥㰾牢㸯椼灮瑵槧㵤渢浡≥琠灹㵥琢硥≴渠浡㵥渢浡≥撓慬獳∽慮敭•慶畲㵥∢洠硡敬杮桴∽㔲∵†楳驅∽㘳⼢㰾琯㹤⼼牴㰾牴㰾摴㰾慬敢潦㵲攢憖汩㸢ⵅ慍汩㰺灳湡撓慬獳∽憖摮䍔慬獳㸢㰪猯慰㹮⼼慬敢㹬戼⽲㰾湩異⁴摩∽浥楡≬琠灹㵥琢硥≴渠浡㵥攢憖汩•汣獡㵳攢憖汩•慶畲㵥∢洠硡敬杮桴∽㔲∵†楳驅∽㘳⼢㰾琯㹤⼼牴㰾牴㰾摴㰾湩異⁴琠灹㵥猢扵業≴†慮敭∽潰瑳•慶畲㵥倢獯≴㸯⼼摴㰾琯㹲⼼懾汢㹥⼼潦浲
I tried to use String
instead of StringBuffer
, but that didn't help. I also tried to set the content type header as follows
response.setContentType("text/html;charset=UTF-8");
before getting the response writer, but that did also not help.
In the DB there are no issues with the data as I have used the same data for 2 different purposes. In one I get correct output , but in other I get the above junk. I have used the above code in JSP using scriptlets. I have also given content type for the JSP.
是'StringBuffer'中的垃圾字符嗎?你可以粘貼一些示例輸出嗎?這聽起來像是一個編碼問題。 – 2010-11-01 12:32:56