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.
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.
See more on this question at Stackoverflow