Wednesday, July 12th, 2006

J2EE and AJAX: AJAX with Servlets

Category: Java, Programming

The use of J2EE in development work has been growing at a staggering pace over the last few years. Developers are finding its environment and capaitilities to be just what they need. One thing that it’s missing though, is a good method to interact with the user. Sure, there are the usual web interaction methods, but why use those when you can incorporate Ajax into your application? Not sure how? Check out this new tutorial from DevArticles for the full scoop on using Ajax either client-side or as a servlet at server-side.

AJAX provides asynchronous communication service through JavaScript and XML. Thus a good combination can be formed by using AJAX at client-side and a servlet at server-side, providing a non-obtrusive, responsive and highly interactive web experience.

In this discussion, I will focus on utilizing such a winning combination. The first sections will detail the steps required for setting up an application for utilizing AJAX along with a servlet. In the last section I will develop a registration module that will use AJAX to check the availability of the username.

They start off with the basics – how to set up the XMLHttpRequest object and create an interface to pass the information to it. Next up is handling the state change of the object (when something, anything happens) and the generation of the XML response. Finally, they thie things together into a chunk of code that can send a message and retrieve the results from the request.

Posted by Chris Cornutt at 3:07 pm

3.3 rating from 54 votes


Comments feed TrackBack URI

JSP is a really nice way to send back an XML (JSP) file.
First 2 lines:

Throw in some JSTL, Custom Tags, and EL Expressions and it’s like touching god.

Comment by Ken Fehling — July 12, 2006

First 2 lines:

Comment by Ken Fehling — July 12, 2006

Trying with pre:

Comment by Ken Fehling — July 12, 2006

Here, this time it should work:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<%@page contentType=”text/xml;charset=ISO-8859-1″%>

Comment by Ken Fehling — July 12, 2006

What some of us need is a simple Ajax framework for not so smart people, such as the following:

Comment by Venkat — July 13, 2006

To me, any tutorial that suggests setting up the XmlHttpRequest object by hand is a disservice. Sure, maybe it’s good background information to know but why put yourself throught the pain and hassle? My current recipe for AJAX success in the Java world is this:

Prototype.js sending Ajax.Request(…) calls to Struts Actions that return JSONObjects in the response body which can then be directly evaluated by the javascript client and presented to the user with judicious use of effects.

This is, of course, nothing new and it is nothing close to touching God, but it’s a much better working environment than what I believe you’d get if you followed that tutorial.

Comment by Aaron Campos — July 13, 2006

Res 2006/07/13

质疑百度企业软件事业部解散声明杨澜收购美国《今日娱乐》Wired杂志收购Wired网站 耗资2500万美元互联网首脑圈名人博客玩砸了,欺骗点击率的草根精英也玩丢了,现在搞起了博客圈子,翻杅

Trackback by Wangtam — July 14, 2006

Servlets and AJAX works very well together. is build upon AJAX and Servlet interconnection

Comment by LP — July 19, 2006

I have written one simple Ajax program using servlet response. I searched a lot over net, but couldnt get any easy example. So, I have posted that
simple ajax program at my blog.

Binod Suman

Comment by BinodSuman — May 9, 2009

Leave a comment

You must be logged in to post a comment.