Hi,
I'm new to JSP. I want a sample code to call a java class on button click in jsp.

That you want in the way you want it cannot be done.
If you want to call a java method, after the page has rendered, by clicking a button you need to submit the form, to a servlet or jsp (preferably a servlet) and there you can call your java method. Then you must redirect to whatever page you want with the results.

Check the first Read Me post of the jsp forum about MVC:

"JSP database connectivity according to Model View Controller (MVC) Model 2"

How do you solve the issue. Kindly reply.