Question: 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.

Answer: 
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](http://code.google.com/webtoolkit/) 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.
I found the way:

```
function myjavascriptfunc(){

<% // put java code %>
}

```