javascript - Calling java server side method using jquery - Stack Overflow

I need to call java class method inside jquery , how do i do that ?For more understanding Ex:Class Foo{

I need to call java class method inside jquery , how do i do that ?

For more understanding Ex:

Class Foo{
      public static void letsCall(){
          // Do something here ...
      }
}

I want to call this letsCall() Method from jquery.

I need to call java class method inside jquery , how do i do that ?

For more understanding Ex:

Class Foo{
      public static void letsCall(){
          // Do something here ...
      }
}

I want to call this letsCall() Method from jquery.

Share Improve this question edited Apr 2, 2014 at 6:11 Baby 5,1123 gold badges32 silver badges52 bronze badges asked Apr 2, 2014 at 6:10 User123456User123456 1891 gold badge6 silver badges14 bronze badges 3
  • Expose the method using a servlet and call it. You should consider implementing a proper, simple RESTful web service just to keep it nice and clear. – toniedzwiedz Commented Apr 2, 2014 at 6:13
  • try with jsp like <%=function%> – Mr.G Commented Apr 2, 2014 at 6:18
  • I dont want to use JSP or servlets for this , only jquery call to Java Class... – User123456 Commented Apr 2, 2014 at 6:18
Add a ment  | 

3 Answers 3

Reset to default 2

1 approach:-

in jquery api, to call any backend system , in your case java, you need to do ajax call to invoke your java controller or service.

jquery ajax post call (call your java controller here)

2nd approach:-

if you need java class to take part in your jsp formation , you can go for custom tags, in your case you can look for jsf framework which basically bind your user events to your controller.

other frameworks - springmvc bind your jsp attributes to its corresponding models, in this case no need to use jquery , you can achieve it through spring custom tags.

spring mvc example

spring custom tags example

spring custom tag example

Calling a backend Java method from JavaScript/jQuery in JSP

Calling Java inside JavaScript Function

There are maybe a half dozen more similarly worded questions, please google first!

Check out DWR. We use it a lot to do this kind of thing and it works well. It wraps all the ajax stuff so you don't have to worry about it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744401041a4572388.html

相关推荐

  • javascript - Calling java server side method using jquery - Stack Overflow

    I need to call java class method inside jquery , how do i do that ?For more understanding Ex:Class Foo{

    6天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信