使用jquery调用java服务器端方法 [英] Calling java server side method using jquery

查看:103
本文介绍了使用jquery调用java服务器端方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在jquery中调用java类方法,我该怎么做?

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

更多理解Ex:

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

我想称之为 letsCall()方法来自jquery。

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

推荐答案


1方法: -

1 approach:-

在jquery api中,要调用任何后端系统,在你的情况下java,你需要做ajax调用来调用你的java控制器或服务。

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(调用你的java控制器)这里)


第二种方法: -

2nd approach:-

如果你需要java类参与你的jsp编队,你可以去自定义标签,在你的情况下你可以找到jsf框架,它基本上将你的用户事件绑定到你的控制器。

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.

其他框架 - springmvc将你的jsp属性绑定到相应的模型,在这种情况下不需要使用jquery,你可以通过spring自定义标签实现它。

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自定义标签示例

这篇关于使用jquery调用java服务器端方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆