XML Tutorials
  Home arrow XML Tutorials arrow Handling Data for Ajax with JSON
FaxWave - Free Trial.
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML TUTORIALS

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    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"

        "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app>
        <servlet>
           
    <servlet-name>AjaxResponseServlet</servlet-name>
            <servlet-class>
          com.AJAXbook.servlet.AjaxResponseServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
       
    <servlet-mapping>
            <servlet-name>AjaxResponseServlet</servlet-name>
            <url-pattern>/response</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

    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"/>
            </fileset>
        </path>

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

        </target>

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

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

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

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

    </project>

    More XML Tutorials Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Ajax on Java," published by O'Reilly. We...
     
     

    Buy this book now. This article is excerpted from chapter four of the book Ajax on Java, written by Steven Douglas Olson (O'Reilly, 2007; ISBN: 0596101872). Check it out today at your favorite bookstore. Buy this book now.

    XML TUTORIALS ARTICLES

    - 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


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway