使用jquery调用java服务器端方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22802889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Calling java server side method using jquery
提问by User123456
I need to call java class method inside jquery , how do i do that ?
我需要在 jquery 中调用 java 类方法,我该怎么做?
For more understanding Ex:
欲了解更多信息,例如:
Class Foo{
public static void letsCall(){
// Do something here ...
}
}
I want to call this letsCall()
Method from jquery.
我想letsCall()
从 jquery调用这个方法。
采纳答案by pappu_kutty
1 approach:-
1 种方法:-
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 api 中,要调用任何后端系统,在您的情况下是 java,您需要执行 ajax 调用来调用您的 java 控制器或服务。
jquery ajax post call (call your java controller here)
jquery ajax post call(在这里调用你的java控制器)
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.
如果您需要 java 类参与您的 jsp 形成,您可以选择自定义标签,在您的情况下,您可以寻找 jsf 框架,它基本上将您的用户事件绑定到您的控制器。
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.
其他框架 - springmvc 将您的 jsp 属性绑定到其对应的模型,在这种情况下不需要使用 jquery ,您可以通过 spring 自定义标签来实现它。
spring custom tags example
spring 自定义标签示例
回答by Michael Voznesensky
Calling a backend Java method from JavaScript/jQuery in JSP
在 JSP 中从 JavaScript/jQuery 调用后端 Java 方法
Calling Java inside JavaScript Function
There are maybe a half dozen more similarly worded questions, please google first!
可能还有六个类似措辞的问题,请先谷歌!