js怎么调用JAVA方法

JavaScript020

js怎么调用JAVA方法,第1张

一般的浏览器中是无法通过js调用本地java程序的,但是可以调用嵌入到网页的applet的方法。交互方式如下:

<applet codebase = "." width = "400" height  = "400"

  name= "MyApplet" code = "test.applets.MyApplet1.class"> 

<script>

// js访问applet属性:document.appletName.appletField (属性必须是public的) 

// js访问Applet方法:document.appletName.appletMethod (方法必须是public的)

function showLable{

     // 调用test.applets.MyApplet1类的invokeByJS方法 

     document.applets["MyApplet"].invokeByJS('myvalue')

}

</script>

body中部分代码如:<center><font size="4" color="red">吊灯</font><input type="button" id="diaodeng" value=<%=state[0]%>onclick="dianji1()"><br><br><br><br></center>

script中的的代码如下:

function dianji1(){

var abc=document.getElementById("diaodeng")

if(abc.value=="on"){

abc.value="off"

}

else{

abc.value="on"

}

}

要求是通过点击按钮能够调用java类中的方法从而修改数据库中的内容

或者

$("button").click(function(){

$.post("/foo/usr/11",function(data){

})

})

jquery post方法调用java方法修改数据库