Java call inside JavaScript function

Please tell me can we call java inside the 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>
+5
source share
8 answers

While the answer "No" is technically correct based on the wording of the question. You can read on AJAX. This is a way for javascript to query your internal code (in this case, Java).

Javascript is the client side, that is, it is launched by the user's browser. Java runs on your server. For client-side javascript to interact with the Java backend server, you need to make a request to the server.

+6
source

My question to you will be: "What are you trying to do, and what do you expect to see?".

, . - JSP, JVM , - Javascript, . , , : , System.out.println Hiiiiiiiii , . , Javascript :

function getScreenDimension() {




}

Javascript. JSP Javascript . "" Java- , AJAX. Java- .

UPDATE

, , Java. . , AJAX. .

+2

JSP . , . JSP . JS.

JSP script, JavaScript.

JSP, JavaScript, , JavaScript HTTP- ( location.href, , , Ajax ..)

+2

, , . , <% %> , . , javascript , . , , . , AJAX, - , .

0
0

, . JSP <%= %>. :

<aui:script use="aui-datepicker">
    AUI().use('aui-datepicker', function(A) {
        new A.DatePickerSelect({
            calendar : {
                dates : [ '<%="1/1/1970" %>' ],
            }
        }).render('#myDatePicker');
    }); 
</aui:script>
0
source

You can. In JSF, you can use the PrimeFaces component p: remoteCommand , which will contain an action method. Call that remoteCommand by its name from JS and the java method will be executed.

JSF Page

    <p:remoteCommand name='rmt' action="#{bean.doWork()}"/> 

In javascript

    function callJava {rmt();}
0
source

Use JSP Code

    <% 
    // Respond to the application with 1) result, 2) update, and 3) updateid values
    String result = "blablabla";

    out.print(result); 
    %>
-2
source

All Articles