Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在窗格中显示charset=windows-1252的html_Java_Html_Jeditorpane - Fatal编程技术网

Java 如何在窗格中显示charset=windows-1252的html

Java 如何在窗格中显示charset=windows-1252的html,java,html,jeditorpane,Java,Html,Jeditorpane,我从一个服务器得到一个html响应,我想在一个窗格中显示它。但是响应将字符集设置为windows-1252,这似乎不会导致任何html呈现。(当我把它注释掉时,它呈现的很好) 所以,一个解决方案是在我尝试显示它之前解析它,但是我想知道是否有已知的bug或者我可以做些什么来避免编辑响应。谢谢 如果您想尝试它(如果您注释掉第3行,您将看到它显示): publicstaticvoidmain(字符串参数[]) { 字符串html=“”+ "" + "" + "" + "" + "" + “你好,世界”

我从一个服务器得到一个html响应,我想在一个窗格中显示它。但是响应将字符集设置为windows-1252,这似乎不会导致任何html呈现。(当我把它注释掉时,它呈现的很好)

所以,一个解决方案是在我尝试显示它之前解析它,但是我想知道是否有已知的bug或者我可以做些什么来避免编辑响应。谢谢

如果您想尝试它(如果您注释掉第3行,您将看到它显示):

publicstaticvoidmain(字符串参数[])
{
字符串html=“”+
"" +
"" +
"" +
"" +
"" +
“

你好,世界

”+ "" + ""; JEditorPane编辑器=新的JEditorPane(“文本/html”,html); editor.setEditable(false); JScrollPane=新的JScrollPane(编辑器); JFrame f=新JFrame(“字符集=windows-1252”); f、 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f、 getContentPane()。添加(窗格); f、 设置大小(800600); f、 setVisible(真); }
有一个错误:

但是您可以使用指令忽略
META
标记:

JEditorPane editor = new JEditorPane();
editor.setContentType("text/html");
editor.getDocument().putProperty("IgnoreCharsetDirective", true);
editor.setText(html);
editor.setEditable(false);

JScrollPane pane = new JScrollPane(editor);
JFrame f = new JFrame("charset=windows-1252");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(pane);
f.setSize(800, 600);
f.setVisible(true);

那就够了!谢谢。
JEditorPane editor = new JEditorPane();
editor.setContentType("text/html");
editor.getDocument().putProperty("IgnoreCharsetDirective", true);
editor.setText(html);
editor.setEditable(false);

JScrollPane pane = new JScrollPane(editor);
JFrame f = new JFrame("charset=windows-1252");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(pane);
f.setSize(800, 600);
f.setVisible(true);