I use Java and call a webservice. When I display the response on my web page with :
String str=answer.toString();
label.setText(str);
It’s okay. But when I want to call a JavaScript function, I fail. I used a code which worked ( here ) and changed it to do what I want.
So in the beginning of my code I have
import netscape.javascript.JSException;
import netscape.javascript.JSObject;
then later
try {
jso = JSObject.getWindow(this); // line 38
} catch (JSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
then later
jso.call("affiche1",new String[] {String.valueOf(str.trim()).trim()}); // line 110
“affiche” is my js function which should display the answer on my web page.
When I run it with Eclipse I get the errors
netscape.javascript.JSException
at netscape.javascript.JSObject.getWindow(Unknown Source)
at Test2.init(Test2.java:38)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)java.lang.NullPointerException
at Test2$1.actionPerformed(Test2.java:110)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
The lines 38 and 110 are precised above.
When I run it in Mozilla, I get the errors
XML or text declaration not at start of entity Line 1
"<html xmlns="http://www.w3.org/1999/xh...teReply></soap:Body></soap:Envelope></"
and
An invalid or illegal string was specified” code: “12
file:///L:/pwe/onload_refresh/ngonl/pub/htmlkit/effects.js
Line 22
I have not found something similar on the web. I just found advices : to drop the whitespace in my xml file, but I think it is not that because there is no problem when I display it inside the applet (and I don’t know exactly how doing that, I am a very beginner in java).
I really don’t understand because I have the line
jso.call("affiche1",new String[] {String.valueOf(str.trim()).trim()});
I drop white spaces before and after with trim() – two are not necessary, but I wanted to be sure to drop it ! I think the errors in Eclipse are not important because I got the same with something which works (she may be here because it s calling javascript, and javasript is not in my eclipse project ?).
I find it very strange because I have a string, and not a XML, right ? So I really dont understand why this error is raised…
Thank you very much for any help and advice.
Problem solved :
it was the innerHTML, because there were non-HTML tags inside.
So, instead of doing directly a innerHTML, I call this function in javascript :
I parse it (string to dom), then I get the value I want (into tag1 tag), then I edit the html. In fact, that is what I wanted. Testing to display the entire string was not a good idea, and couldnt be done because of the < tag > inside.
Hope it will help someone.