Open GoogleCodeExporter opened 9 years ago
Solved it by using HtmlEncoder:
---------------------------------------
import java.io.IOException;
public class HtmlEncoder {
public static final HtmlEncoder INSTANCE = new HtmlEncoder();
public void encode(CharSequence sequence, Appendable out) throws IOException {
for (int i = 0; i < sequence.length(); i++) {
char ch = sequence.charAt(i);
if (Character.UnicodeBlock.of(ch) == Character.UnicodeBlock.BASIC_LATIN) {
out.append(ch);
} else {
int codepoint = Character.codePointAt(sequence, i);
// handle supplementary range chars
i += Character.charCount(codepoint) - 1;
// emit entity
out.append("&#x");
out.append(Integer.toHexString(codepoint));
out.append(";");
}
}
}
}
---------------------------------
---------------------------------
@Override
protected void error( HttpServletRequest request, HttpServletResponse response, Exception cause )
throws ServletException, IOException
{
if ( response.isCommitted() )
{
throw new ServletException( cause );
}
response.setContentType( "text/html; charset=windows-1251" );
StringBuilder html = new StringBuilder();
html.append( "<html>" );
html.append( "<title>Error</title>" );
html.append( "<body bgcolor=\"#ffffff\">" );
html.append( "<h2>XDocReport Servlet: Error report generation</h2>" );
html.append( "<pre>" );
String why = cause.getMessage();
if ( why != null && why.trim().length() > 0 )
{
//html.append( why );
HtmlEncoder.INSTANCE.encode(why, html);
html.append( "<br>" );
}
StringWriter sw = new StringWriter();
cause.printStackTrace( new PrintWriter( sw ) );
//html.append( sw.toString() );
HtmlEncoder.INSTANCE.encode(sw.toString(), html);
html.append( "</pre>" );
html.append( "</body>" );
html.append( "</html>" );
response.getOutputStream().print( html.toString() );
}
-------------------------------
Now it is in UTF-8
Original comment by MrSo...@gmail.com
on 16 Jan 2013 at 8:11
Hi,
Many thank's to have fixed this problem. Just one question, do you need force
the encoding with "charset=windows-1251" ?
I will do apply your fix, as soon as possible.
Regards Angelo
Original comment by angelo.z...@gmail.com
on 16 Jan 2013 at 8:19
You mean this?
response.setContentType( "text/html; charset=windows-1251" );
No I don't really need this, it displays correct without this charset.
But if you have time see Issue 212.
Original comment by MrSo...@gmail.com
on 16 Jan 2013 at 9:22
Original issue reported on code.google.com by
MrSo...@gmail.com
on 16 Jan 2013 at 8:09