Jump to content
Sign in to follow this  
Elnof

Javascript accessing Java?

Recommended Posts

My Javascript code is unable to access any of my java code. Where's my problem?java script:

function getFile(pURL) {    var text;        document.getElementById('mainText').innerHTML = "<p>Loading Text...</p>";  text = document.textReadApp.javascriptCommandReadFile(pURL);    if(text != "-1") {      repairText(text);  }  else {      document.applets("textReadApp").innerHTML = "<p>Error in load</p>";  }}function repairText(string) {     var text;   var text2;   var homeLink = "<a onClick=\"getFile('addon/text/home.ntk')\" class=\"homeLink\">Home</a>";   text = String.replace(/~h~/gi, homeLink);   text2 = text.replace(/~p~/gi, "<p>")   text = text2.replace(/~!p~/gi, "</p>");   text2 = text.replace(/~img~/gi, "<img src=\"");   text = text2.replace(/~!img~/gi, "\" />");   text2 = text.replace(/~sup~/gi, "<a href=\"#footNotes\"><div class=\"sup\">");   text = text2.replace(/~!sup~/gi, "</div></a>");   text2 = text.replace(/~n~/gi, "<br />");   text = text2.replace(/~l~/gi, "<hr class=\"textLine\" />");      placeText(text);}function placeText(finText) {   document.getElementById('mainText').innerHTML=finText;}

And my java:

import java.awt.*;import java.io.*;import javax.swing.*;public class webTextReader extends JApplet {    /**     *      */    private static final long serialVersionUID = 1L;    /**     * @param args     */          public String javascriptCommandReadFile(String path) {          try{              // Open the file that is the first               // command line parameter              FileInputStream fstream = new FileInputStream(path);              // Get the object of DataInputStream              DataInputStream in = new DataInputStream(fstream);                  BufferedReader br = new BufferedReader(new InputStreamReader(in));              String strLine;              String result = null;                            //Read File Line By Line              while ((strLine = br.readLine()) != null)   {                // Print the content on the console                result += strLine;              }              //Close the input stream              in.close();              return result;            }          catch (Exception e){//Catch exception if any                System.err.println("Error: " + e.getMessage());            }        return "-1";     }         public static void main(String args[])      {          }}

Everytime I try to run it, I get:

Error: Object doesn't support this property or method.

Why is it doing this? I've tried it on IE7 and FireFox 2.0.2.

Share this post


Link to post
Share on other sites

document.textReadApp.javascriptCommandReadFile(pURL);I believe there should be either a getElementById in there, or the document.applets collection.

Share this post


Link to post
Share on other sites

I've tried both of those, and I got the same result. I'll try again tomorrow, but I don't think that it will help.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...