Chapter 2. JavaScript for Ajax


Ajax is centered around the clever use of JavaScript. It isn't a web framework, like Struts or Tapestry, and it isn't some fancy new technology with a cool acronym; Ajax boils down to using JavaScript to interact directly with the web server, avoiding the submit/response cycle all too familiar to web users.

Java programmers have typically avoided JavaScript, sometimes for good reasons and sometimes for bad ones. Certainly, adding another layer of scripting to a JSP page can only add to the confusion. However, JavaScript runs entirely on the browser and is therefore very fast. There's no waiting for the server to generate a response: JavaScript can compute a result and update the page immediately.

Ajax adds server interaction, but without the Submit button. Whenever data is needed, the JavaScript in the web page makes a request, and the server replies with databut not another HTML page. The server returns data that the JavaScript displays in the existing page. The result is that your web application feels a lot more like a desktop application. In short, you can achieve a rich application experience in your web pages by using Ajax.

This book won't attempt to teach JavaScript, or even to analyze its pros and cons. I assume that you have had some exposure to JavaScript. If you're new to it, check out JavaScript: The Definitive Guide, by David Flanagan (O'Reilly). This is the best JavaScript reference available. JavaScript isn't Java, though reading JavaScript code shouldn't be hard for any Java developer. You will find that the JavaScript used in this chapter is pretty easy; as long as you can get through the syntax, you shouldn't need to review or study JavaScript just yet.




Ajax on Java
Ajax on Java
ISBN: 0596101872
EAN: 2147483647
Year: 2007
Pages: 78

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net