如何在 Java Web 应用程序中使用 jQuery 学习 AJAX

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/773508/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:42:16  来源:igfitidea点击:

How to learn AJAX using jQuery in a Java web app

javajqueryajaxservlets

提问by Ankur

Can someone point me to tutorials using jQuery to create AJAX apps with Java (servlets). I was looking at the tutorial Implementing Ajax in Java web application using JQuery, which is similar to what I need, but it doesn't include most of the detail.

有人可以指点我使用 jQuery 使用 Java(servlet)创建 AJAX 应用程序的教程。我正在查看使用 JQuery 在 Java Web 应用程序中实现 Ajax的教程,这与我需要的类似,但它不包含大部分细节。

If you know of a good tutorial, text + graphics or video or know the main steps and can outline them, that would be appreciated. I know it seems like something that should be easy to Google and come up with 100s of answers, but it's not, which is why I am asking. Thanks.

如果您知道一个好的教程、文本 + 图形或视频,或者知道主要步骤并可以概述它们,那将不胜感激。我知道这对 Google 来说似乎应该很容易并能提供 100 多个答案,但事实并非如此,这就是我问的原因。谢谢。

回答by ólafur Waage

I think many of the tutorials out there are making things way to complicated. Just remember that AJAX requests are no different that other requests.

我认为那里的许多教程都使事情变得复杂。请记住,AJAX 请求与其他请求没有什么不同。

See if this onehelps you out.

看看这个能不能帮到你。

回答by Adam Jaskiewicz

He's assuming a lot about his audience. The tutorial is written for people who know Java web app development, at least to some basic level, and have dealt with a little Javascript, perhaps even tried a jquery tutorial or two. I think this is fine, as it means that someone who isfamiliar with all of that will be able to jump right in and get to the meat of the matter without having to filter out all the stuff they already know. Perhaps a paragraph at the top explaining those assumptions would be a good idea, but I digress...

他对他的观众做了很多假设。本教程是为那些了解 Java Web 应用程序开发的人编写的,至少有一些基本的水平,并且已经处理了一点 Javascript,甚至可能尝试过一两个 jquery 教程。我觉得这是好的,因为这意味着有人谁熟悉所有这一切将能马上加进去,并获得问题的肉,而不必过滤掉所有他们已经知道的东西。也许顶部的一段解释这些假设是个好主意,但我离题了......

What jumps out at me as a potential gotcha is that the weather servlet is in the ajaxify package:

一个潜在的问题让我想到的是,天气 servlet 位于 ajaxify 包中:

                  V------see?
<servlet-class>ajaxify.WeatherServlet</servlet-class>

so you will need to make sure you specify that package in WeatherServlet.java, or change it to match what you are doing. Also, no mention is made of including the jquery.jsfile in the <head>of your JSP:

因此,您需要确保在 中指定该包WeatherServlet.java,或更改它以匹配您正在执行的操作。此外,没有提到jquery.js<head>您的 JSP中包含该文件:

<script type="text/javascript" src="jquery.js" />

Obviously you will need to include code around the form to make it into a complete html page, so you will have a <head>element into which to put the various <script>tags. You will also need to complete the WeatherServletclass as in any other Java web application:

显然,您需要在表单周围包含代码以使其成为一个完整的 html 页面,因此您将有一个<head>元素来放置各种<script>标签。您还需要WeatherServlet像在任何其他 Java Web 应用程序中一样完成该课程:

public class WeatherServlet extends HttpServlet
{
  ...

BTW, I think it's a great tutorial. I am familiar with Servlets and JSP, know the concept behind AJAX, knew of jQuery, and have messed with jQuery for about ten minutes. The tutorial perfectly filled the gaps in my knowledge I had around how all those pieces fit together. I had no idea jQuery could make AJAX so easy to deal with, and this is going to get me to look a lot more seriously into jQuery.

顺便说一句,我认为这是一个很棒的教程。我熟悉 Servlets 和 JSP,知道 AJAX 背后的概念,知道 jQuery,并且已经使用 jQuery 大约十分钟。该教程完美地填补了我关于所有这些部分如何组合在一起的知识空白。我不知道 jQuery 可以让 AJAX 如此容易处理,这会让我更认真地看待 jQuery。