Duplicate :
|
Name: gm110360 Date: 05/31/2002 FULL PRODUCT VERSION : java version "1.4.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92) Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode) FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : Problem occurs when using the setText method of JEditorPane, and providing a string containing the source of an html page. If the string contains a meta tag which sets the content-type, the page will not display. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Change in the source "url to test page" to actual URL's of the test pages. This is the source for a working test: <html> <head> <title>Test</title> </head> <body> <h1>This is a test</h1> </body> </html> 3. run the code. It will display "This is a test" 4. By adding the meta line change the code to this: <html> <head> <title>Test</title> <META HTTP-EQUIV="Content-Type" CONTENT="text/html"> </head> <body> <h1>This is a test</h1> </body> </html> 5. Run again. Nothing will be shown. EXPECTED VERSUS ACTUAL BEHAVIOR : Without the offending meta tag the page will show. If the content-type is removed from the meta tag it will still show. However, if a meta tag which sets the content-type is given, nothing will be shown in the JEditorPane. This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.*; import javax.swing.*; import java.net.*; import java.io.*; public class TestFrame extends JFrame { BorderLayout borderLayout1 = new BorderLayout(); JScrollPane jScrollPane1 = new JScrollPane(); JEditorPane jEditorPane1 = new JEditorPane(); public TestFrame() { setSize(500, 400); setVisible(true); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } this.validate(); try { URL url = new URL("url to test page"); InputStream is = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer page = new StringBuffer(); while ((line = br.readLine()) != null) { page.append(line); page.append('\n'); } br.close(); System.out.println(page.toString()); jEditorPane1.setContentType("text/html"); jEditorPane1.setText(page.toString()); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { TestFrame testFrame = new TestFrame(); } private void jbInit() throws Exception { this.getContentPane().setLayout(borderLayout1); this.setDefaultCloseOperation(3); jEditorPane1.setText("jEditorPane1"); this.getContentPane().add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(jEditorPane1, null); jEditorPane1.setEditable(false); } } ---------- END SOURCE ---------- CUSTOMER WORKAROUND : Filter out the meta tag! (Review ID: 145369) ======================================================================