klatuu 0 Newbie Poster

I have some experience with Java and Javascript and searching this forum has helped me tremendously, but haven't been able to find this exact problem explicitly. In a nutshell: I want to call a java class straight from javascript i.e. use a java class in javascript without OBJECT or APPLET.

Here's what I'm experimenting with:

function screenSize() {
alert("Screen Dimension\n" + "  width:"
    + java.awt.Toolkit.getDefaultToolkit().getScreenSize().width
    + " height:" + java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
}

which is an example given on http://www.rgagnon.com/javadetails/java-0170.html. This is hooked to a button on a page. When clicking the button I (in essence) get:

"A Runtime Error has occured at line 35: 'java' is undefined."

I'm assuming that my path is incorrect or missing and there's a PATH or CLASSPATH or something I've overlooked. Once I get this code working, I'll replace the screen dimension stuff with my own java class.

What I'm trying to do in essence is grab the current web page's source, pass the source to my java class, parse a list of numbers from the page source, merge page's list of numbers with another list of numbers stored in a spreadsheet and create another spreadsheet containing the merged list. I can do everything now EXCEPT make this call to my client-side java class.

I'd eventually like to move the javascript into a bookmarklet so that the user will be able to click a favorite on the appropriate page and have magic happen because of my own java classes manipulating the data from the screen. For various reasons political and technical, I'm stuck using IE6-7 and have to work with scraping the web page in the browser and processing everything on the client -- no sever side action for me! I can assume that a JRE 6 will be available.

Is this a path issue? Is what I want even possible and if so, how? And how will packages work with all this?

Thanks. Any advice or examples will be muchly appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.