开发者

java to javascript communcation

开发者 https://www.devze.com 2023-04-01 16:52 出处:网络
i am trying to pass value from javascript to java (applet ), but everytime its coming out to be null .

i am trying to pass value from javascript to java (applet ), but everytime its coming out to be null .

my java class :

package com.vaannila.utility;


import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import prefuse.util.ui.JPrefuseApplet;

public class dynamicTreeApplet extends JPrefuseApplet {

    private static final long serialVersionUID = 1L;
    public static int i = 1;
    public String dieasenameencode;
//  System.out.println("asjdjkhcd"+dieasenameencode);
    public void init() {
        System.out.println("asjdjkhcd"+dieasenameencode);
        System.out.println("the value of i is " + i);
        URL url = null;
//      String ashu=this.getParameter("dieasenmae");
//      System.out.println("the value of the dieases is "+ashu);
        //Here dieasesname is important to make the page refresh happen 

        //String dencode = dieasenameencode.trim();
        try {
            //String dieasename = URLEncoder.encode(dencode, "UTF-8");
            // i want thi开发者_JAVA技巧s piece of the code to be called 
            url = new URL("http://localhost:8080/docRuleToolProtocol/appletRefreshAction.do?dieasename="+dieasenameencode);
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setUseCaches(false);
            InputStream ois = con.getInputStream();
            this.setContentPane(dynamicView.demo(ois, "name"));
            ois.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException f) {
            f.printStackTrace();

        } catch (IOException io) {
            io.printStackTrace();
        }
        ++i;
    }

}

my javascript :

function showSelected(value){
alert("the value given from"+value);
var diseasename=value;
alert(diseasename);
document.decisiontree.dieasenameencode="diseasename"; 
}


I don't think that you can directly access variables in the applet, but you can definitely call methods in the applet. Try making a setter for your variable and calling that from JavaScript.

0

精彩评论

暂无评论...
验证码 换一张
取 消