Wednesday, July 12th, 2006
J2EE and AJAX: AJAX with Servlets
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.












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.
First 2 lines:
Trying with pre:
Here, this time it should work:
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<%@page contentType=”text/xml;charset=ISO-8859-1″%>
What some of us need is a simple Ajax framework for not so smart people, such as the following: http://www.cbsdf.com/ps_blog/why-other-frameworks.htm
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 script.aculo.us 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.
Res 2006/07/13
质疑百度ä¼ä¸šè½¯ä»¶äº‹ä¸šéƒ¨è§£æ•£å£°æ˜Žæ¨æ¾œæ”¶è´ç¾Žå›½ã€Šä»Šæ—¥å¨±ä¹ã€‹Wiredæ‚å¿—æ”¶è´Wired网站 耗资2500万美元互è”网首脑圈å人åšå®¢çŽ©ç ¸äº†ï¼Œæ¬ºéª—ç‚¹å‡»çŽ‡çš„è‰æ ¹ç²¾è‹±ä¹ŸçŽ©ä¸¢äº†ï¼ŒçŽ°åœ¨æžèµ·äº†åšå®¢åœˆå,翻æ…
Servlets and AJAX works very well together. http://www.litha-paint.com is build upon AJAX and Servlet interconnection