JTextPane with servlets
I am using a JTextPane as a browser for simple servlet testing using a simple webserver on localhost and HttOutputStream.
The textpane displays HTML ok except when returned by a servlet in which case I see the HTML markup. Connecting on an external browser like IE shows the servlet response correctly as HTML.
The problem only happens when the servlet is called by a simple form; it works ok if called by hyperlink or the servlet address (+params) is typed into the address bar.
Looking through the code that I wrote 5 years ago I see that i use a URLConnection to retrieve the data from the server from a hyperlink listener and then call setText() on the textpane. In the case of an HTML form, the server replies directly to the JTextPane which seems to forget it should display the returned text as HTML and not plain text. This worked before i migrated it to Java 1.6. There must be some tweek required, but what ?
Any ideas ?
Indeed, I found the contentType had been set to text/plain instaed of text/html
How to avoid this ?
Well, I have managed to detect when it happens and quickly reset the page properly. It is barely noticeable so quite a good fix. But I would still like to know how to avoid it !