在JavaScript函数中调用Java [英] Calling Java inside JavaScript Function

查看:662
本文介绍了在JavaScript函数中调用Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我是否可以在javascript函数中调用java?

Please tell me if we can call java inside javascript function ?

<HTML><HEAD></HEAD><BODY>
    <SCRIPT>
        function getScreenDimension() {
            <% System.out.println("Hiiiiiiiii"); %>
        }
    </SCRIPT>
    <FORM>
        <INPUT type="button" value="call Java method direct"  onClick = "getScreenDimension()">
    </FORM>
</BODY></HTML>


推荐答案

虽然否的答案在技术上是正确的关于问题的措辞。您可能想要阅读AJAX。这是javascript向您的后端代码发出请求的一种方式(在本例中为Java)。

While the answer of "No" is technically correct based on the phrasing of the question. You may want to read up on AJAX. It is a way for javascript to make a request to your backend code (in this case Java).

Javascript是客户端,这意味着它由用户的浏览器运行。 Java正在您的服务器上运行。为了使客户端javascript与后端Java交互,您需要向服务器发出请求。

Javascript is client side, meaning it is run by the user's browser. Java is running on your server. In order for the client side javascript to interact with the backend Java, you need to make a request to the server.

这篇关于在JavaScript函数中调用Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆