• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invoking java function with java script Onclick event

 
AmitKashyap kashyap
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Is it possible to invoke java fucntion in JSP through java script OnClick event.
I am able to invoke javascript function through OnClick event but not able to do the same with java function.

Thanks in Advance,
Amit
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it is not possible.
 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But then, you can always call the Java function by:
1) importing the necessary Java class inside your JSP.
2) Calling the Java function from within a scriptlet which you can place inside a Javascript function which is invoked on the onClick event.
The net result is the same as invoking a Java function from an onClick event.
 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to put it more simply, just do a onClick submit form
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling the Java function from within a scriptlet which you can place inside a Javascript function which is invoked on the onClick event.
The net result is the same as invoking a Java function from an onClick event.


Not so!

The JSP is executed on the server long long before the resulting response is sent back to the client. The embedded Java call is executed as the page is being constructed and in no way can be invoked as a part of the onclick handler.

"Embedding" a Java function in a JS function only serves to "write" the results of the Java function to the body of the JS function. Which is not even remotely the same thing as "calling" the Java function as part of the JS function.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic