XML Tutorials

  Home arrow XML Tutorials arrow Handling Data for Ajax with JSON

Handling Data for Ajax with JSON
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5

    Table of Contents:
  • Handling Data for Ajax with JSON
  • Running the Application on Tomcat
  • Passing Data with JSON
  • Changing the JavaScript for JSON



    Handling Data for Ajax with JSON

    (Page 1 of 4 )

    This article concludes a three-part series that focuses on XML and JSON for Ajax. It shows you how to build and run an Ajax character decoder application, and how to pass data with JSON. It is excerpted from chapter four of the book Ajax on Java, written by Steven Douglas Olson (O'Reilly, 2007; ISBN: 0596101872). Copyright 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Building the Application

    Now that we have reviewed the code, let's build it and try it out. It's very similar to the example in the previous chapter, and because I don't like to overwrite my work, I put the new application in its own directory tree. The directory structure I used is shown in Figure4-2.

    This is just a guide so you can see how I built the sample. You can name your directories differently as long as you know how to configure the application server properly.

    Figure 4-2.  Directory structure for Ajax Character Decoder (second version)

    The web.xml file for the project is presented in Example 4-8.

    Example 4-8. web.xml

    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"


    The build.xml file for the project is shown in Example 4-9.

    Example 4-9. build.xml

    <?xml version="1.0"?>
    <project name="AJAX-CODECONVERTER " default="compile" basedir=".">

        <property environment="env"/>
        <property name="src.dir" value="src"/>
        <property name="test.dir" value="test"/>
        <property name="war.dir" value="war"/>
        <property name="db.dir" value="db"/>
        <property name="class.dir" value="${war.dir}/WEB-INF/classes"/>
        <property name="test.class.dir" value="${test.dir}/classes"/>
        <property name="lib.dir" value="${war.dir}/WEB-INF/lib"/>
        <property name="webapp.dir"
                  value="${env.TOMCAT_HOME}/ webapps/ajaxcodeconverter-lab2"/>

        <path id="ajax.class.path">
            <fileset dir="${lib.dir}">
                <include name="*.jar"/>

        <target name="testenv">
            <echo message="env.TomcatHome=${env.TOMCAT_HOME}"/>
            <echo message="env.ANT_HOME=${env.ANT_HOME}"/>


        <target name="init">
            <mkdir dir="${class.dir}"/>
            <mkdir dir="${test.class.dir}"/>

        <target name="compile" depends="init"
                description="Compiles all source code.">
            <javac srcdir="${src.dir}" destdir="${class.dir}" debug="on" 

        <target name="clean" description="Erases contents of classes dir">
            <delete dir="${class.dir}"/>
            <delete dir="${test.class.dir}"/>

        <target name="deploy" depends="compile"
                description="Copies the contents of web-app to destination dir">
            <copy todir="${webapp.dir}">
                <fileset dir="${war.dir}"/>


    More XML Tutorials Articles
    More By O'Reilly Media

    blog comments powered by Disqus


    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax

    Developer Shed Affiliates


    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap