views:

2571

answers:

3

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.

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.

+1  A: 

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.

See if this one helps you out.

Ólafur Waage
+3  A: 

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 is familiar 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...

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

                  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.js file in the <head> of your 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 WeatherServlet class as in any other Java web application:

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.

Adam Jaskiewicz
So you would you recommend changing <servlet-class>ajaxify.WeatherServlet</servlet-class> to <servlet-class>WeatherServlet</servlet-class>
Ankur
Well, I wouldn't recommend it or not recommend it; I'm just mentioning that it's there and that it might be easy to miss. Either change it to that and use the default package, or make sure your WeatherServlet is in that package. It's more a general Java thing than a jQuery AJAX thing, so not really important to the tutorial.
Adam Jaskiewicz
A: 

I am facing the problem in the tutorial mention above , my calls go to servlet but response is not visible on html page

kashif