3

I have a dynamic web project. In src folder I have Java class with couple of methods. Let us suppose index.html file has two buttons.on click of the button how can I call the Java class. Is there any possibility of doing so?

halfer
  • 19,824
  • 17
  • 99
  • 186
user3007385
  • 153
  • 4
  • 15
  • 2
    Did you try with `JSP`? – Rong Nguyen Jun 10 '14 at 10:52
  • or do you mix up Java with JavaScript (this is not the same). Java should be not used in normal webpages and you should use a Java framework and Java server (which use JSP) - but you can try a Java applet (may not be very secure and blocked) –  Jun 10 '14 at 10:59

4 Answers4

0

This cannot be done using simple html pages. You should be using JSP files instead which will let you make a call to your JAVA classes methods through directives.

This is common guess since you did not provide much relevant information about your project structure.

tmarwen
  • 15,750
  • 5
  • 43
  • 62
0

Create servlet which will handle get/post requests, invoke your java code and return result.

http://docs.oracle.com/cd/E19857-01/819-6518/abxbh/index.html http://www.oracle.com/technetwork/java/servlet-142430.html

Kasper Ziemianek
  • 1,329
  • 8
  • 15
0

You have to use JSP. Here is a simple tutorial that could be useful to start. JSP tutorial

Good luck!

csadan
  • 291
  • 1
  • 3
  • 13
0

You should work with frameworks. I recommend you SPRING MVC. It`s very good and easy to use. For calling a java class you need jQuery and the framework.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38