Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Parameters from Java to JavaScript

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I'm trying to pass parameters from java to java script.
When I compile I got thie message " JSObjectr class " not found.
Please how can I set the CLASSPATH to point to JSOject.class?
do i have to go to settings/control panel/system and then to enviroment tab and then type at the end of the value of CLASSPATH after the semicolomn he following "c:\JSOject.class "
my jdk1.2.2 is in drive D.
Please anyhelp with it.also
I'm getting an error " JavaScript error :type 'javascript' into location for details " in the bottom of my screen of my browser(Netscape).
What about setting the class path???
Thanks all for your time.
Here is the codes:
import java.awt.*;
import java.applet.*;
import netscape.javascript.JSObject;
import java.lang.*;
public class array extends java.applet.Applet
{
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(426,266);

//}}
try
{
win= JSObject.getWindow(this);
}
catch(Exception e){}
}
//{{DECLARE_CONTROLS
//}}
String testStr;
Integer testInt;
Character testChar;
JSObject win;
Object testArray[]=new Object[3];
void create()
{
testStr=new String("Test string");
testInt=new Integer(1);
testChar=new Character('a');
testArray[0]=testStr;
testArray[1]=testInt;
testArray[2]=testChar;
try
{
win.call("extractArray",testArray);
}
catch(Exception e){}
}
public void paint(Graphics g)
{
g.drawString("here is an applet ",50,25);
}

}
//***********************************************************
Here is the HTML file
<HTML>
<HEAD>
<SCRIPT>
function extractArray(var1,var2,var3)
{
alert ("java return string: " + var1);
alert ("java return int : " + var2);
alert ("java return char : " + var3);
}
</SCRIPT>
</HEAD>
<BODY>
<center>
<HEAD>
<form>
<input type=button value=click onClick=document.array.create()>
</form>

<APPLET name = array code=JSObject.class MAYSCRIPT >

</APPLET>
</BODY>
</center>
</HTML>
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is the javascript error? Whatdid you see on the JavaScript console when you typed "javascript:" into the location bar?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply
I'm not sure if that the answer,but I'll tell what I'm getting:
when i compile i got this erroe message:
" C:\moh\array.java:6: Class netscape.javascript.JSObject not found in import.
import netscape.javascript.JSObject; "
Also in Netscape console i got this message:
" Netscape Communications Corporation -- Java 1.1.5
Type '?' for options.
Symantec Java! ByteCode Compiler Version 210.065
Copyright (C) 1996-97 Symantec Corporation
# Applet exception: class array could not be loaded ".
Also i got this message in the satus bar of Netscape
" Javascript error typr 'javascript;into location for details.
Thanks again for your time.
^
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, two things. The first seems to be that you are using the wrong name for the class in the APPLET tag. You say:
<APPLET name = array code=JSObject.class MAYSCRIPT>
but there is no JSObject.class listed in your java. This should probably be:
<APPLET name=array code=array.class MAYSCRIPT>
The "name" attribute of the APPLET tag is only for use by JavaScript so it can tell which applet is which; the "code" attribute is the one which determines which Java class to use.
The second point is that you seem to be unaware of how to get JavaScript to give you more information. When it says type 'javascript:' into location for details" you should click in the location bar at the top of the browser (where it says http://www....), replace whats there with the special keyword "javascript:" (don't forget the colon ':'), and press RETURN. This tells the browser to bring up the JavaScript console, which gives information about Javascript errors. You should see more information about your problem.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks alot for your time,really you teached me alot of good things i didn't know before,thanks.
when i typed javascript: at that location i got this message:
" Javascript error: file:c\final...\array.html,line 17
Java object has no field or method named create.
Really i don't know how to fix it,maybe that related to obtainingand & installing the JSObject class that i don't how to do it.
There is two way by unzipping java_30 or java_40 filews or just by point your CLASSPATH at the archive file.
Would you please tell how to do one of those.
Really i appreciate your time.
Thanks.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is definately the problem I pointed out in my previous post.
you are using the wrong name for the class in the APPLET tag. You say:

<APPLET name = array code=JSObject.class MAYSCRIPT>

but there is no JSObject.class listed in your java. This should be:

<APPLET name=array code=array.class MAYSCRIPT>

JSObject is a class provided by JavaScript to let your Java applets deal with JavaScript values. It should never appear in your JavaScript. Only the names of your Java classes should appear in your JavaScript code.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks again
I still can't fix it unfortunatly,what i did is:
we uncompressed java40 file and i put JSObject.class in the same directory as my java & html file.
what i got is when i compile java file i still get
" C:\FinalBarChartBackup\array.java:5: Class netscape.javascript.JSObject not found in import.
import netscape.javascript.JSObject; "
Also when i write "javascript: in the location bar of the browser
i got this message "Javascript Error:file:c\....\array.html line 16:
Java Object has no field or method named create.
it seems to me something wrong in the java file because of that
netscape package.
Please would you help me with this.
i appreciate that alot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic