次のコードがあります。
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
public class ScratchPad {
public static void main(String args[]) throws Exception {
String html ="<html>"+
"<head>"+
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"/>"+ // this is the problem right here
"<title>Error 400 BAD_REQUEST</title>"+
"</head>"+
"<body>"+
"<h2>HTTP ERROR: 400</h2><pre>BAD_REQUEST</pre>"+
"<p>RequestURI=null</p>"+
"<p><i><small><a href=\"http://jetty.mortbay.org\">Powered by jetty://</a></small></i></p>"+
"</body>"+
"</html>";
JFrame f = new JFrame();
JEditorPane editor = new JEditorPane();
editor.setEditable( false );
editor.getDocument().putProperty( "Ignore-Charset", "true" ); // this line makes no difference either way
editor.setContentType( "text/html" );
editor.setText( html );
f.add( new JScrollPane(editor, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) );
f.pack();
f.setVisible( true );
}
}
実行すると、フレームが空白であることがわかります。ただし、メタ タグから「; charset=ISO-8859-1」を削除すると、HTML が表示されます。これを防ぐために私ができる理由と方法 (私が制御できない HTML 文字列を手動でハッキングする以外に...)。
編集 #1 - putProperty( "Ignore-Charset", "true" ) 残念ながら違いはありません。