用JAVA编写Ajax代码
我想用java编写ajax代码,即我想使用ajax的功能而不使用ajax。我正在寻找一些可以做到这一点的JAVA API。
就像我们通过JAVA程序发布网页数据一样,我想通过JAVA程序执行ajax操作。
请建议。
I want to write ajax code in java i.e. i want use the functionality of ajax without using ajax. I'm looking for some API of JAVA which can do so.
Like we post data of a web page through JAVA program similarly I want to perform operation of ajax through JAVA program.
Please suggest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
Google Web Toolkit 是用于编写 AJAX 应用程序的纯 Java 框架。
Google Web Toolkit is Java-only framework for writing AJAX aplications.
Echo 是 gwt 的替代品
Echo is an alternative to gwt
您可以使用 jQuery 来实现此目的。在 jQuery 中,你有一个很棒的 form 插件,它可以不显眼地将现有表单更改为 ajaxform。
HTML(在 JSP 中):
JS((在)直接在 JSP 中):
Java((在)直接在
myservlet
后面的 Servlet 的doPost()
方法中):如果您想要更进一步,您可以在 Servlet 中使用 Gson 来转换完整的 Java对象到 Javascript 对象表示法 (JSON)。这样您就可以在 Javascript 中以类似 javabean 的方式访问数据。
You can use jQuery for this. In jQuery you have the great form plugin which unobtrusively changes an existing form into an ajaxform.
HTML (in JSP):
JS ((in)directly in JSP):
Java ((in)directly in
doPost()
method of the Servlet behindmyservlet
):If you want to get some steps further, you can use Gson in Servlet to convert complete Java objects to Javascript object notation (JSON). This way you can access the data the javabean-like way in Javascript.
如果您的应用程序在浏览器上运行并且是 Web 应用程序,则可以使用 GWT。如果您的应用程序是核心java应用程序..您可以简单地创建一个 HttpURLConnection 并使用它。
If your application is running on browser and its a web application, you can go with GWT. If your application is a core java application.. you can simply create a HttpURLConnection and use it.
JavaServer Faces (JSF) 2.0 应该能够在幕后使用 AJAX 对页面进行部分更新。在我看来,这似乎就是你所需要的。
我认为现在运行支持 JSF 2.0 的服务器的最简单方法是使用最新版本的 Glassfish。
JavaServer Faces (JSF) 2.0 should be able to do partial updates of a page in place, using AJAX under the covers. It sounds to me as if that is what you need.
I think the easiest way to get a JSF 2.0 capable server running right now, is using the latest version of Glassfish.
有很多基于 Java 的 AJAX 框架。
Apache Struts [复杂的 AJAX 标签(通过集成 DOJO 工具包)]
Direct Web Remoting 是一个直接从 Javascript 代码调用 Java 方法的框架。
Guise™ Framework - 优雅的服务器端组件架构,不需要开发人员编写 HTML 或JavaScript
GWT - 用于编写 AJAX 应用程序的 Java 软件开发框架
JAXCENT - Just-Java 框架和 AJAX API
IT Mill< /a> - 用于在服务器端使用 Java 语言开发 Web 应用程序的 Ajax 框架
甚至更多 JAVA AJAX 框架
There are plenty of Java based AJAX frameworks out there.
Apache Struts [complex AJAX-tags (by integrating DOJO-toolkit)]
Direct Web Remoting is a framework for calling Java methods directly from Javascript code.
Guise™ Framework - elegant server-side component architecture that doesn't require developers to write HTML or JavaScript
GWT - Java software development framework that makes writing AJAX applications
JAXCENT - Just-Java Framework and API for AJAX
IT Mill - Ajax framework for developing web applications for with Java language at server-side
and even more JAVA AJAX Frameworks
我建议您查看 DWR - Easy Ajax for Java:
它使您能够以最小的努力对您的 Web 应用程序进行 ajax 化。
它不是一个全新的网络框架;它只专注于 ajaxification,允许您保留和使用现有的 Web 框架。
如果您想使用像 JSF 这样的“较重”的 Web 框架,可以使用支持 ajax 的 JSF 框架,例如 IceFaces 和RichFaces 提供开箱即用的 ajax。
I suggest you take a lok at DWR - Easy Ajax for Java:
It enables you to ajax-ify your web application with minimal effort.
It is not a complete new web-framework; it focuses solely on ajaxification, allowing you to keep and use your existing web framework.
If you want to use a "heavier" web framework like JSF, there exist ajax-ready JSF frameworks like IceFaces and RichFaces with provide ajax out-of-the-box.
您可以将表单提交给servlet,当servlet响应时,您可以使用jquery或原型javascript框架通过Ajax调用函数从服务器获取数据。
我尝试了一下,运行很顺利!
祝你好运!
you can submit form to servlet, when servlet response, you using jquery or prototype javascript framwork to get data from server by using Ajax call function.
I tried it and it run smoothly!
Good luck!
快速回答是 GWT。然而,你为什么要这样做呢? JavaScript 与 Java 类似。如果您了解 Java,那么您可以轻松编写 JavaScript 代码。使用 JavaScript 的优点是你会更加灵活,不会被单一工具所束缚。使用 GWT 生成 JavaScript (AJAX) 代码并不自然。
The quick answer is GWT. However, why would you want to do this? JavaScript is similar to Java. If you know Java, then you can easily write JavaScript code. The advantage of using JavaScript would be that you would be more versatile and would not be locked into a single tool. Using GWT to generate JavaScript (AJAX) code is not natural.