2

we have one servlet program which is using the HTML code inside the servlet program i.e

HTML.append("<html>");
HTML.append(lnTag);
HTML.append("<head>");
HTML.append(lnTag);
HTML.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
String titalsLang = resourceBundle.getString("eayslip.tan.title");  
HTML.append("<title>"+resourceBundle.getString("eayslip.tan.title")+"</title>");</i>

// and list of codes... 

out.print(HTML);
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);

I am getting the Chinese character from the property file while debugging into the code. But once the response is sent to the page, in the html page we are getting question mark ?????.

We have no problems with English characters and they are displaying correctly.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Amit Kumar
  • 33
  • 5
  • http://stackoverflow.com/questions/20670034/how-to-display-chinese-character-in-html should solve your problem. – Sinistralis Sep 11 '15 at 06:05
  • Welcome to Stack Overflow. Please read the editor help page so you can format your posts more readably in future:http://stackoverflow.com/editing-help – Jon Skeet Sep 11 '15 at 06:05
  • @ Sinistralis i used same concept , which you have suggest a link to me. But i am getting the same as previous issue . – Amit Kumar Sep 11 '15 at 06:10
  • Try setting to your HTML. –  Sep 11 '15 at 06:26

1 Answers1

1

I suspect the problem is that you're setting the content type - including the encoding - after calling HttpServletResponse.getWriter(), assuming that's where out comes from.

From the documentation of ServletResponse.setContentType:

This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter has been called or after the response has been committed.

Basically, you should set all the headers in the response before you call getWriter... and if you're calling getOutputStream rather than getWriter, you shouldn't... use a writer for text data, and a stream for binary data.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks for your reply. I follow up your instruction . Now, Chinese character is displaying on web page . :) – Amit Kumar Sep 11 '15 at 13:13