Can I write Java logic in JavaScript code?

11,211

Solution 1

If you want the logic to execute on the client side, then (aside from applets etc) the logic will have to be written in JavaScript. There are tools such as GWT which convert Java to JavaScript, which may help you.

Another alternative is to use AJAX - you don't redirect the whole page when you want to execute the logic, but your JavaScript calls back to the server (which then executes the logic in Java, in your case) and then potentially alters one piece of the UI based on the response.

Solution 2

I found the way:

function myjavascriptfunc(){

<% // put java code %>
}
Share:
11,211
harshit
Author by

harshit

Updated on June 04, 2022

Comments

  • harshit
    harshit almost 2 years

    Can I write Java logic inside JavaScript? If yes, how?

    I don't have liberty to make a new class and redirect it there on click of button.