harshit
harshit

Reputation: 7951

Can I write Java logic in JavaScript code?

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.

Upvotes: 2

Views: 11302

Answers (2)

harshit
harshit

Reputation: 7951

I found the way:

function myjavascriptfunc(){

<% // put java code %>
}

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1502166

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.

Upvotes: 3

Related Questions