JEditorPane with text/html content-type still displaying as plain-text?
Hello all,
I recently started work on a very basic HTTP GET program that gets the HTML source of a page and, using a JEditorPane, displays the page as normal (i.e. like a browser would).
Anywhoo, the HTTP GET is fine, and the source is loaded into a String called "html". Then I do this:
displayArea.createEditorKitForContentType("text/html");
displayArea.setText(html);However the content appears in the editor pane as plain-text (i.e. the HTML code appears as-is, not in a 'compiled' form).
Any ideas why this is?
Thanks,
Tristan
Thanks for the replies, however the setContentType didn't work either. When I changed the code to what you suggested, nothing got inserted into the editor pane at all (i.e. no HTML - nor plain-text?). More of the code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.Socket;
import java.util.Scanner;
public class ClassName extends JFrame implements ActionListener
public JTextField urlIn, pageIn;
public JButton go;
public JScrollPane scrollPane;
public JEditorPane displayArea;
public JPanel topPanel;
public String url, page, html;
public int index;
public ClassName()
setSize(1230,680);
setLayout(new BorderLayout());
JPanel topPanel = new JPanel();
topPanel.setLayout(new FlowLayout());
urlIn = new JTextField(18);
pageIn = new JTextField(18);
JButton go = new JButton("Go!");
topPanel.add(urlIn);
topPanel.add(pageIn);
topPanel.add(go);
add(topPanel, BorderLayout.NORTH);
displayArea = new JEditorPane();
displayArea.setEditable(false);
add(displayArea, BorderLayout.CENTER);
go.addActionListener(this);
urlIn.addActionListener(this);
setVisible(true);
public static void main(String args[])
new ClassName();
public void actionPerformed(ActionEvent e)
if( e.getActionCommand() == "Go!" )
url = urlIn.getText();
page = pageIn.getText();
if (url != null && page != null )
try
final int HTTP_PORT = 80;
Socket s = new Socket(url, HTTP_PORT);
InputStream inStream = s.getInputStream();
OutputStream outStream = s.getOutputStream();
Scanner in = new Scanner (inStream);
PrintWriter out = new PrintWriter(outStream);
out.print("GET " + page + " HTTP/1.0\n\n");
out.flush();
while( in.hasNextLine() )
String input = in.nextLine();
html = html + input;
s.close();
catch (Exception exception)
System.out.println("Error: " + exception);
displayArea.setContentType("text/html");
displayArea.setText(html);
urlIn.setText("");
pageIn.setText("");
else
System.out.println("Please enter something!");
}Am baffled as to what the problem is? :-(
Thanks,
Tristan
Similar Messages
-
Hi I am in trouble with JAX-WS 2.1.2M1
I try to call my Webservice like this:
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, "http://spblue.liberty:8084/SPBlue/GlobalLogoutService");
Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
SOAPMessage message = XmlUtil.getSOAPMessageFromString(request);
SOAPMessage response = disp.invoke(message);when my disp invokes I get following Exception which seems to as a little Problem, anyway I don�t know how to get rid of this Exception.
com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html;charset=utf-8 Supported ones are: [text/xml]
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:116)
at com.sun.xml.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:280)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:158)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:74)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:559)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:518)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:503)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:400)
at com.sun.xml.ws.client.Stub.process(Stub.java:234)
at com.sun.xml.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:166)
at com.sun.xml.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:192)
at test.service.Logout.requestLogout(Logout.java:115)
at test.service.Logout.main(Logout.java:149)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]
my ServiceClass is:
@ServiceMode(value=Service.Mode.MESSAGE)
@WebServiceProvider( targetNamespace="http://spblue.liberty:8084/wsdl/globalLogout")
public class GlobalLogoutServiceImpl implements Provider<SOAPMessage> {
* Web service operation
public SOAPMessage invoke( SOAPMessage logoutRequest ){
return logoutRequest;
}So how can I set the Charachter set before invokikng the service.
Or how can I change the Service to accept UTF-8.
Well, I don�t know.
Any help is welcome.Hi,
I don't know if this can help you, but I had a similar problem while invoking a web service. Eventually, I found out that the server was returning an html error page, and not the expected xml answer.
That's why the client code raises such an error... It means that the MIME type of the anser is text/html (for the html page) and not the text/xml type of the 'nominal' web service answer.
You can verify this by using a proxy to intercept the http request and answer involved in this web service invocation (use Fiddler for instance). Then, you will see that the server responds by sending an html page saying that something is wrong.
Hope this helps...
Sam -
Hello,
I hope you can help me. I've imported all my emails from Eudora into Outlook 2010 but I have a couple of problems.
All emails that I've imported which had attachments with them have a notice on them saying the attachment has been blocked. I can always browse to the folder whereb my old attachments are stored, but this is still inconvenient.
Secondly, all my messages that I've sent in the past (html) are being displayed in plain text, which is making them difficult to read because of all the html tags being displayed.
Also with emails that I've sent in the past- there is no record of any attachments being sent with messages which I know had attachments with them.
Any ideas? I've trawled google and had no luck except finding programs that cost $70 that can import everything properly.
DavidDavid:
I know this is a very old thread, but did you every figure out a way to fix the formatting of imported Eudora mail?
I just "upgraded" from Eudora to Outlook 2010 ...
and have 10 years worth of HTML formatted e-mail that now shows up as plain text with embedded html formatting ...
apparently it is a long-running problem that has roots in the way Eudora formats messages ...
Outlook and other e-mail clients all seems to have issues with importing and do not properly recognize HTML-formatted messages from Eudora ... very sad that I can no longer really "read" my old e-mail at this point ... :-(
See closing paragraphs here: http://its.uiowa.edu/support/article/2800
Same problem over at Mozilla going back 10+ years ... not sure if they fixed it..........
https://bugzilla.mozilla.org/show_bug.cgi?id=3157 -
Hello All,
I am on BI 4.0 SP6.
I am login to Advance Analysis Office using sso with Authentication : Windows AD, but when i login errors occurs:
Client found response content type of 'text/html;charset=iso-8859-1', but expected 'text/xml'.
The request failed with the error message:
I have done all settings and configuration for SSO as per following notes:
http://service.sap.com/sap/support/notes/1631734
http://service.sap.com/sap/support/notes/1646920
http://service.sap.com/sap/support/notes/1794675
Earlier i was getting Login Exception Error WSE : 99999, i did some changes, after that the above error is coming
Does anybody knows the solution?
KR,
MDrefer the below note
1785270 - How to configure AD SSO for Advance Analysis for MS Office with Business Objects BI 4.0 -
Font color issue with inserted HTML content in JTextPane (HTMLEditor)
Hi everyone,
I have a very serious issue with the HTMLEditor I'm developping. This editor is a little bit special since it is intended to edit blocks of HTML content that are loaded when the editor is initialized.
You can in fact decide to keep this loaded HTML content or start a new HTML document from scratch. Alright, now my issue is the following :
When text is loaded, it's properly rendered. I have a functionality which let's you see the HTML code from the HTML document used in the editor, so I can check and see if code is correct, and yes, it's correct.
The problem is that when I try to change the color attribute of some text on my loaded content, nothing happens ! I don't know what's the matter with this bug, I only have it with the color attribute, with every other attribute everything's fine (font, size, etc.)
The funny thing is that, after I change another attribute for loaded content, like font family, then changing color attribute funcionnality starts to work again !
I've also noticed that I don't have any of these problems when I start my HTMLDocument from scratch (when I create a new HTML document and start typing text).
Another weird thing, is that I have a feed-back feature in my editor which reflects attributes for text over which the caret is positionned. For example, if you put caret over red text, the color combo box displays a red value, you know, just like in MS Word. Well, with my loaded content if I have a red text color and I decide to put it in green, the color combo box displays the green value when I click over text for which I have changed color, but in my JTextPane it's still red !! And when I try to see the HTML code generated nothing has changed, everything is still red !
There is something really strange here, this means that when I get the attributes of the loaded text from the HTMLDocument, color appears to be green, but when it gets rendered in the JTextPane it's still red and when it gets anlyzed to produce the corresponding HTML code, these changed attributes are not taken into account.
But the most weird thing above all, is that I don't have this bug everytime, sometimes I start my HTML editor applet and it works fine, and some other times this color issue is bakc there. Is this a known bug for Swing API or not ?
=============
This is more or less my technique :
//I declare a global reference to my HTMLDocument
HTMLDocument _docHTMLDoc;
//Create a JTextPane
JTextPane _tpaEditor = new JTextPane( );
//Set type content to automatically select HTMLEditorKit
_tpaEditor.setContentType("text/html");
//Get a referene to its HTMLEditorKit
HTMLEditorKit _kitHTMLEditor = (HTMLEditorKit) _tpaEditor.getEditorKit( );
//I then have a function to create new documents
void newDocument(){
_docHTMLDoc = (HTMLDocument) _kitHTMLEditor.createDefaultDocument();
_tpaEditor.setDocument(_docHTMLDoc);
//I do other stuff wich are not important to be shown here
//I then have another function to load content
void loadContent(){
//I get content from a HashMap I initialized when I started my applet
String strContent = (String)_mapInitParameters.get("html_content");
//I set content for my editor
_tpaEditor.setText(strContent);
//Notice.. I have tried many other ways to load this text : via HTMLEditorKit and its insertHTML method, I
//have also tried to store this content in some reader and make HTMLEditorKit read it... and nothing,
// I always get the bug
//To change color it goes like this :
JComboBox _cboColor = new JComboBox();
//I correctly initialize this combo with colors
//then I do something like this
ActionListener _lst = new ActionListener(){
public void actionPeformed(ActionEvent e){
Color colSel = (Color) _cboColor.getSelectedItem();
MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setForeground(mas,colSel);
setAttributeSet(mas);
_cboColor.addActionListener(_lst);
//Set Attributes goes something like this
private void setAttributeSet(javax.swing.text.AttributeSet atrAttributeSet) {
//Get current 'End' and 'Start' positions
int intCurrPosStart = _tpaEditor.getSelectionStart();
int intCurrPosEnd = _tpaEditor.getSelectionEnd();
if(intCurrPosStart != intCurrPosEnd){
//Apply attributes to selection
_docHTMLDoc.setCharacterAttributes(intCurrPosStart,intCurrPosEnd - intCurrPosStart,atrAttributeSet,false);
else{
//No selection : apply attributes to further typed text
MutableAttributeSet atrInputAttributes = _kitHTMLEditor.getInputAttributes();
atrInputAttributes.addAttributes(atrAttributeSet);hi, friend!
try this:
void setAttributeToText(JTextPane pane, int start, int end, Color color) {
MutableAttributeSet new_att = new SimpleAttributeSet();
StyleConstants.setForeground(new_att,color);
HTMLDocument doc=(HTMLDocument)pane.getDocument();
doc.setCharacterAttributes(start,end,new_att,false);
It works fine in my Application, hope will work in yours, too.
good luck. -
HTML links won't display in Dynamic Text Field
I am loading external text files in dynamic text fields on my
webage. These texts contain html links (<a href="page.html"
target="_blank">Click Here</a> and I have "render as HTML"
on and "selectable" off in my dynamic text field. Also, I am
loading a CSS file. Not only do I not have a hand cursor, but I do
not even have any of the text from that piece of html code down.
What is going on with this? Please respond asap, as I have been
struggling with this for a day now. Here is the Actionscript for
loading the CSS:
var flash_css = new TextField.StyleSheet();
flash_css.load("styles.css");
flash_css.onLoad = function(success:Boolean) {
if (success) {
zloc_txt.styleSheet = flash_css;
} else {
trace("Error loading CSS file.");
var zloc_lv:LoadVars = new LoadVars();
zloc_lv.load("zloc.txt");
zloc_lv.onLoad = function(success:Boolean) {
if (success) {
zloc_txt.text = this.content;
} else {
trace("unable to load text file.");
zloc_txt.html = true;
zloc_txt.editable = false;
_global.styles.TextArea.setStyle("backgroundColor" ,
"transparent");
_global.styles.TextArea.setStyle("border styles" , "solid");
Here is a sample of the text file code:
&content=<span class="headline">Northwest Arkansas
Locations</span>
121 Main St.
Russellville, AK 77801
(626) 111-1111<br />
<html><a href="
http://www.mapquest.com"
target="_blank">Click Here for Driving
Directions</a></html><br />
Thanks for the help,
ChuckThe error is here:
zloc_txt.text = this.content;
Even if you rendered the textfield as HTML, you still need to
tell flash that the variable you are inserting is HTML. Therefore
you need to use the htmlText property.
zloc_txt.htmlText = this.content; -
In SharePoint 2010 I created workflows that used the 'Create list Item' Action, which then set the Content Type ID (so I could create documents of various types in a document library).
We just switched to the SharePoint 2013 platform, and now the drop down for Content Type ID is blank in all of the workflows that are still using the SharePoint 2010 platform. Is there any way to create a list item with specific content
type? Even if I could just input a string into that field instead of using this blank drop-down. Please help!Hi Sarah,
According to your description, my understanding is that you cannot create a new list item with a specific content type using SharePoint 2010 Platform Workflow.
I tested the same scenario in my environment, and the Create List Item worked fine with the specific content type.
How did you create the content type?
Please check if the content type is added to the list/library the workflow associated with.
Best regards.
Thanks
Victoria Xia
TechNet Community Support -
Html iView is still displayed in foreground after layer navigation
Hi Experts,
in my model I have an layer with a form view and a html view. After navigation back to another layer, the opened window of the html view is still displayed in the foreground. When the model is compiled with Flash (flex), it works correctly. When compiling with Flash (Flex2) it doesn`t work. Does someone have an idea?Hi,
In your model you are given navigation control as Default ,just give any other navigation option Ex Tab and try .
And for me its working fine.
If u think i did not got ur problem just send the screen shots of Both Flex and Flex2
Regards,
Govindu -
Email with HTML (content/type). Is it possible?
Hello!
I have this script to send e-mail form my PDF form:
event.target.submitForm({cURL
:"mailto: "+ vEmail +"?subject=" + vSubject +"&body=" + vBody,cSubmitAs:"PDF",cCharset:"utf-8"});
I would like to send e-mail with content/type HTML. Is it possible? When open my Outlook, the message is in format simple text, but I don't want. I want the format HTML.
Thanks!Hello my friend Niall. How are you?
So, Not is it possible, right?
I try search on the internet about the function submitform, but I didn't found anything about the HTML. I need this because the user going to put a html table when reply the e-mail for me.
Thanks. -
External Content Type not displaying List.
I am getting the following Error when i go to the External Content Type List i Created.
Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Microsoft SharePoint Foundation-compatible HTML editor such as Microsoft SharePoint Designer. If the problem persists, contact your Web server administrator.
When i open it up in Sharepoint Designer and look at the page i get this error.
soap:ServerException of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.An error has occurred.
I'm connecting to a SQL Server with sql server credentials. I'm able to see the tables and columns in the Data Source Explorer.
The permissions for the Content Type are all authenticated Users with everything checked.Hi,
How did you supply username and password to the external content type?
As i know, there are four options (user's identity, BDC's identity, impersonate windows identity, impersonate custom identity), you cannot directly input the SQL username and password.
I suggest you to use impersonate custom identity.
Before using it, you need to create a new target application ID in secure store service application. and select
user name and password for filed type at second step. after that, you need to set credentials for this target application ID to input your sql user name and password there.
Then you need to input this target application ID at connection properties (both default and client tabs) of the external content type.
Regards,
Seven -
How to change content/type from applicaiton/xml to text/xml??
Hi B2B Gurus,
Now that i have worked out file transfer. I was now trying to post the same document onto a HTTP URL.
I see in the headers that the
Content-Type=application/XML
However i need the Content-Type to be text/XML
Where can i get this changed?
Edited by: user773213 on Apr 8, 2009 4:48 AMi tried it but it still shows the same content-type
***************************B2B.LOG************************************************
2009.04.08 at 18:45:29:500: Thread-10: Repository - (INFORMATION) BIND VARS = (5B7A966871774858A1C935F4ADEECA85-95-1, 95, 1, N, http://ap604fin.us.oracle.com:7787/HTTPService/Receiver, <0AB05E5912085DE6D600000082D60500@AS2_Mycompany>, null, null, , Processing, oracle.tip.repos.core.driver.BinaryImpl@10bbd42, , null, , oracle.tip.repos.core.driver.BinaryImpl@1b6772a, null, null, null, HTTP, , 1.0, Wed Apr 08 18:45:29 GMT+05:30 2009, , Message-ID=<0AB05E5912085DE6D600000082D60500@AS2_Mycompany>
Content-Transfer-Encoding=binary
MIME-version=1.0
From=AS2_Mycompany
Receipt-Delivery-Option=file://localhost/ORACLE_HOME\MyCompany
Disposition-Notification-To=[email protected]
AS2-To=AS2_Supplier1
User-Agent=AS2 Server
Date=Wed, 08 Apr 2009 13:15:17 GMT
AS2-Version=1.1
AS2-From=AS2_Mycompany
Content-Type=application/XML; name=ShipOrder
Connection=close
, null, 0AB05E5912085DE72520000082D60600, null, 3C4DF09FF3304FA698C287DA35154FDB, 826050DF70374FF389E372DB6D126D46)
2009.04.08 at 18:45:29:906: Thread-10: Repository - (DEBUG) CatalogDriver.writeObjectList()
*********************************************************************************** -
Getting the html content before browser displays it
Hi,
I have a nagging problem which i am trying hard to solve.
I have a jsp file which gets hundreds of rows from database. I want to capture the html content before the browser displays that. How can I achieve it. ?
Please tell us the solution as soon as possible. we have stopped the work.
Thanks & Regards,
A S N Murthy
[email protected]
[email protected]Hi !
continuing with my previous mail...
Is it okay with you if you use save the Data to be rendered in an XML ? (if you just need all the data).
You've written you will have "hundreds of rows from database".
In case you think of saving the data in an XML format, you can have all that data in a structured manner on the server side. And later you could use the XML file in any way you want. i.e. convert it into an html using xalan, etc. or use the XML file to access the data instead of a DB transaction all over again...
I guess this might be a better approach than saving the HTML that will be generated by the JSP.
Anyway, it depends on your requirement.
regards,
Rahul C Tiwary -
Render xml and html content type in single jsp
I have 2 jsps, one jsp(a.jsp) is throwing content-type as HTML and other JSP(b.jsp) is throwing content-type as xml. I am making use of xsl to render the xml content in html format. But the problem is that i want to include b.jsp in a.jsp, and when i do so b.jsp doesn't make use of xsl for its rendering rather it displays the contents haphazardly.
Plese help if somebody knows the solution.Below the following line ..
<html:form action="addContact">Add this new form field..
<html:hidden name="flag" value="0"/>Needless to say that this String variable flag should be defined in your ActionForm.
Next, instead of ...
<html:submit property="parameter"><bean:message key="ok.company" /></html:submit>Put this ...
<input type="button" name="xyz" onClick="callSubmit(1);" value='<bean:message key="ok.company" />'>Then add a JS function as below ...
<script>
function callSubmit(flg)
document.forms[0].flag.value=flg;
document.forms[0].submit();
</script>Finally in your ActionServlet, you need to find the value of the ActionForm variable flag via request.getParameter("flag").
In case the value is set to 1, then it means that you need to send the particular row to DB. You may add additional flag values to correctly identify theparticular row which you may want to send to DB.
Hope you got it.
-Rohit -
I cannot create a site-template in my own language (danish) and deploy a site based on the template.
I created a template from a "fresh" SharePoint project site with no tampering.
When trying to deploy a new site based on the templat I get the following error:
In Danish:
Beklager, men noget gik galt
Det blev fundet et navn på en dubletindholdstype "billede".
Tekniske oplysninger
Fejlfinding af problemer med Microsoft SharePoint Foundation.
Korrelations-id: 96646c9c-3213-a088-c6c4-537b0815313c
Dato og klokkeslæt: 21-06-2014 10:23:36
In English:
Sorry, something went wrong
A duplicate content type name "billede" was found.
Technical Details
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 0b656c9c-52ee-a088-c6c4-5132070e3c4e
Date and Time: 21-06-2014 10:31:35Need details from ULS logs about Correlation ID: 0b656c9c-52ee-a088-c6c4-5132070e3c4e
Check below:
http://social.technet.microsoft.com/Forums/sharepoint/en-US/e955e737-e12e-4afa-b446-bb6e0f05e9b1/duplicated-content-type-error-creating-a-sharepoint-2010-site-from-a-custom-site-template?forum=sharepointgeneralprevious
http://aramacciotti.wordpress.com/2012/04/04/the-case-of-the-duplicated-contenttype/
http://community.office365.com/en-us/f/154/t/69416.aspx
If this helped you resolve your issue, please mark it Answered -
In my project I am using SharePoint Online 2013 and there is a custom list with two content types. While creating a new item in that list, can we show the content type drop down list along with other columns? While editing an item I am able to view the content
type dropdown in the edit form associated with the list. Can we enable the same for the default newform as well?In my project I am using SharePoint Online 2013 and there is a custom list with two content types. While creating a new item in that list, can we show the content type drop down list along with other columns? While editing an item I am able to view the content
type dropdown in the edit form associated with the list. Can we enable the same for the default newform as well?
Maybe you are looking for
-
I Made a new icloud account bc forgot my username and email and now I can't access bc says I have too many accounts on phone please help!
-
How do i download acrobat x1 trial on windows 7 64 bit
Download of acrobat xi trial on windows 7 64 bit appears to work then pops up with a message saying computer incompatibale with this version of the software - help!
-
Add "make unique symbol" button and context menu option
I often want to make a variation of an existing symbol that is already positioned on the page. Unless I'm missing something, the steps are to duplicate existing symbol in the symbols palette, then replace the selected symbol instance, using the "repl
-
Profit Centre Hierarchy Change and Profit Centre Budget
Hello Friends For better view of Profit Centre Reports we are planing to change the Profit Centre Hierarchy. I wanted to know that, are there some Specific Points which we have to take care of, before changing the Hierarchy? Will some other settings
-
How to recover an iphoto book from backup
Hello, My wife managed to accidentally delete a 75 page iphoto book she's been working on for months. I have a backup of our iphoto library at an offsite location (read: not a time machine) and am in the process of transferring a copy of it to my lo