Download JSON plugin for struts2 from http://code.google.com/p/jsonplugin/downloads/list
Create Samples by using the following steps:
1) Create File - New - Project - JSON-STRUTS2
2) create necessary folders and files such as
src
package named com.apache.struts ( as per ur wish give name) under src
Action class under this package -- say JSONWithStruts2.java
lib -- copy necessary jar files including JSON plugin.
jsp
create jsp files under jsp -- say UserInfo.jsp
config
create struts.xml file under config.
WEB-INF
web.xml under WEB-INF
js
create zxml.js under js
create
build.xml
3) Right click -- Run As -- Ant Script (2nd one). it will display i dailog box.
4) Select war. It will create war under build directoy.
5) copy war file to tomcat/webapps/ directory.
6) start tomcat.
7) Type url in browser like http://localhost:8080/JSON-STRUTS2/jsp/UserInfo.jsp
8) Now you have come to know about working of struts2.
Source Code
JSONWithStruts2.java
package com.apache.struts;
import java.util.ArrayList;
import com.opensymphony.xwork2.ActionSupport;
public class JSONWithStruts2 extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private int userId;
private String userName;
private int userAge;
private String userCity;
private String userEmail;
ArrayList<Integer> ids = new ArrayList<Integer>();
ArrayList<String> names = new ArrayList<String>();
ArrayList<Integer> ages = new ArrayList<Integer>();
ArrayList<String> cities = new ArrayList<String>();
ArrayList<String> emails = new ArrayList<String>();
public String getData()
{
ids.add(1);
names.add("Nathan");
ages.add(20);
cities.add("Bangalore");
emails.add("nathan@dpiq.com");
ids.add(2);
names.add("Rasvi");
ages.add(40);
cities.add("Bombay");
emails.add("rasvi@dpiq.com");
ids.add(3);
names.add("Ramvarma");
ages.add(60);
cities.add("Kolkatta");
emails.add("ramvarma@dpiq.com");
ids.add(4);
names.add("Mathew");
ages.add(20);
cities.add("Delhi");
emails.add("mathew@dpiq.com");
ids.add(5);
names.add("Sulthan");
ages.add(40);
cities.add("Chennai");
emails.add("sulthan@dpiq.com");
int usrId = this.getUserId();
for( int i=0; i<ids.size(); i++ )
{
if( ids.get(i)== usrId )
{
this.setUserName(names.get(i) );
this.setUserAge( ages.get(i) );
this.setUserCity(cities.get(i));
this.setUserEmail(emails.get(i));
break;
}
else
{
this.setUserName("" );
this.setUserAge( 0 );
this.setUserCity("");
this.setUserEmail("");
}
}
return SUCCESS;
}
public int getUserAge() {
return userAge;
}
public void setUserAge(int userAge) {
this.userAge = userAge;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserCity() {
return userCity;
}
public void setUserCity(String userCity) {
this.userCity = userCity;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public int getUserId() {
return userId;
}
}
UserInfo.jsp
<HTML>
<HEAD>
<TITLE>Student Records</TITLE>
<script type="text/javascript" src="../js/zxml.js"></script>
<script language=javascript>
function submitAjax()
{
var ajaxRequest = zXmlHttp.createRequest();
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
if (ajaxRequest.status == 200)
{
renderJSONClass(ajaxRequest.responseText);
}
else
{
alert("Unable to get response!: " + ajaxRequest.responseText);
}
}
}
ajaxRequest.open("GET", "../userinfo.action?userId=" + uid.value );
ajaxRequest.send(null);
return false;
}
function renderJSONClass(myJSONtext)
{
var myObject = eval('(' + myJSONtext + ')');
uname.value = myObject.userName;
uage.value = myObject.userAge;
ucity.value = myObject.userCity;
uemail.value = muObject.userEmail;
}
</script>
</HEAD>
<BODY >
UID <INPUT ID="uid" TYPE="text" onkeyup="submitAjax()" /><BR/><BR/>
NAME <INPUT ID="uname" TYPE="text" /><BR/><BR/>
AGE <INPUT ID="uage" TYPE="text" /><BR/><BR/>
CITY<INPUT ID="ucity" TYPE="text" /><BR/><BR/>
EMAIL<INPUT ID="uemail" TYPE="text" /><BR/><BR/>
</BODY>
</HTML>
zxml.js
/*------------------------------------------------------------------------------
* JavaScript zXml Library
* Version 1.0
* by Nicholas C. Zakas, http://www.nczonline.net/
* Copyright (c) 2004-2005 Nicholas C. Zakas. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*------------------------------------------------------------------------------
*/
/**
* Legacy zXml settings for backwards compatibility.
*/
var zXml = {
useActiveX /*:Boolean*/ : (typeof ActiveXObject != "undefined"),
useDom /*:Boolean*/: document.implementation && document.implementation.createDocument,
useXmlHttp /*:Boolean*/: (typeof XMLHttpRequest != "undefined"),
settings : {
/**
* Does this browser support native XMLHttpRequest?
*/
hasXmlHttp /*:Boolean*/: (typeof XMLHttpRequest != "undefined"),
/**
* Does this browser support ActiveX controls?
*/
hasActiveX /*:Boolean*/: (typeof ActiveXObject != "undefined"),
/**
* Does this browser support native DOM creation?
*/
hasXmlDom /*:Boolean*/: (document.implementation && document.implementation.hasFeature("XML", "1.0")),
/**
* Does this browser support DOM LoadSave?
*/
hasDomLS /*:Boolean*/: (document.implementation && document.implementation.hasFeature("LS", "3.0")),
/**
* Does this browser support DOM LoadSave?
*/
hasDomLSAsync /*:Boolean*/: (document.implementation && document.implementation.hasFeature("LS-Async", "3.0")),
/**
* Does this browser support a native DOMParser?
*/
hasDomParser /*:Boolean*/: (typeof DOMParser != "undefined"),
/**
* Does this browser support a native XMLSerializer?
*/
hasXmlSerializer /*:Boolean*/: (typeof XMLSerializer != "undefined"),
/**
* Does this browser have an XSLTProcessor?
*/
hasXSLTProcessor /*:Boolean*/: (typeof XSLTProcessor != "undefined")
}
};
zXml.ARR_XMLHTTP_VERS = ["MSXML2.XmlHttp.6.0", "MSXML2.XmlHttp.3.0"];
zXml.ARR_DOM_VERS = ["MSXML2.DOMDocument.6.0", "MSXML2.DOMDocument.3.0"];
/**
* Static class for handling XMLHttp creation.
* @class
* @scope public
*/
function zXmlHttp() {
}
/**
* Creates an XMLHttp object.
* @static
* @scope public
* @return An XMLHttp object.
*/
zXmlHttp.createRequest = function ()/*:XMLHttp*/ {
if (zXml.settings.hasXmlHttp) {
return new XMLHttpRequest();
} else if (zXml.settings.hasActiveX) {
if (!zXml.XMLHTTP_VER) {
for (var i=0; i < zXml.ARR_XMLHTTP_VERS.length; i++) {
try {
new ActiveXObject(zXml.ARR_XMLHTTP_VERS[i]);
zXml.XMLHTTP_VER = zXml.ARR_XMLHTTP_VERS[i];
break;
} catch (oError) {
}
}
}
if (zXml.XMLHTTP_VER) {
return new ActiveXObject(zXml.XMLHTTP_VER);
} else {
throw new Error("Could not create XML HTTP Request.");
}
} else {
throw new Error("Your browser doesn't support an XML HTTP Request.");
}
};
/**
* Indicates if XMLHttp is available.
* @static
* @scope public
* @return True if XMLHttp is available, false if not.
*/
zXmlHttp.isSupported = function ()/*:Boolean*/ {
return zXml.settings.hasXmlHttp || zXml.settings.hasActiveX;
};
/**
* Static class for handling XML DOM creation.
* @class
* @scope public
*/
function zXmlDom() {
}
/**
* Creates an XML DOM document.
* @static
* @scope public
* @return An XML DOM document.
*/
zXmlDom.createDocument = function () /*:XMLDocument*/{
//implements createDocument()
if (zXml.settings.hasXmlDom) {
//create the document
var oXmlDom = document.implementation.createDocument("","",null);
//simulate parse error object
oXmlDom.parseError = {
valueOf: function () { return this.errorCode; },
toString: function () { return this.errorCode.toString() }
};
//initialize the error object
oXmlDom.__initError__();
//add an event listener for load
oXmlDom.addEventListener("load", function () {
this.__checkForErrors__();
this.__changeReadyState__(4);
}, false);
//return the object
return oXmlDom;
} else if (zXml.settings.hasActiveX) {
if (!zXml.DOM_VER) {
for (var i=0; i < zXml.ARR_DOM_VERS.length; i++) {
try {
new ActiveXObject(zXml.ARR_DOM_VERS[i]);
zXml.DOM_VER = zXml.ARR_DOM_VERS[i];
break;
} catch (oError) {
}
}
}
if (zXml.DOM_VER) {
return new ActiveXObject(zXml.DOM_VER);
} else {
throw new Error("Could not create XML DOM document.");
}
} else {
throw new Error("Your browser doesn't support an XML DOM document.");
}
};
/**
* Indicates if an XML DOM is available.
* @static
* @scope public
* @return True if XML DOM is available, false if not.
*/
zXmlDom.isSupported = function ()/*:Boolean*/ {
return zXml.settings.hasXmlDom || zXml.settings.hasActiveX;
};
//Get a reference to the XMLDocument or Document class (Mozilla and Opera)
var oDomDocument = null;
if (typeof XMLDocument != "undefined") {
oDomDocument = XMLDocument;
} else if (typeof Document != "undefined") {
oDomDocument = Document;
}
//This block of code is used by both Opera and Mozilla. Perhaps
//Safari will use it as well.
if (oDomDocument) {
//create a ready state for the document
oDomDocument.prototype.readyState = 0;
//setup an empty event handler
oDomDocument.prototype.onreadystatechange = null;
//function to fire whenever the readyState changes
oDomDocument.prototype.__changeReadyState__ = function (iReadyState) {
this.readyState = iReadyState;
if (typeof this.onreadystatechange == "function") {
this.onreadystatechange();
}
};
//initialize the error object
oDomDocument.prototype.__initError__ = function () {
this.parseError.errorCode = 0;
this.parseError.filepos = -1;
this.parseError.line = -1;
this.parseError.linepos = -1;
this.parseError.reason = null;
this.parseError.srcText = null;
this.parseError.url = null;
};
//function load the DOM of another document
oDomDocument.prototype.__loadDom__ = function (oXmlDom) {
while (this.firstChild) {
this.removeChild(this.firstChild);
}
for (var i=0; i < oXmlDom.childNodes.length; i++) {
var oNewNode = this.importNode(oXmlDom.childNodes[i], true);
this.appendChild(oNewNode);
}
};
//determine if the async property is needed
try {
if (typeof oDomDocument.prototype.async != "boolean") {
oDomDocument.prototype.async = true;
}
} catch (e) {}
//overwrite the load() method
//alert(oDomDocument.prototype.load);
oDomDocument.prototype.load = function (sURL) {
this.__initError__();
//use XMLHttp to mimic the correct functionality
var oHttp = zXmlHttp.createRequest();
var oDom = this;
oHttp.open("get", sURL, this.async);
if (this.async) {
oHttp.onreadystatechange = function () {
if (oHttp.readyState == 4) {
oHttp.onreadystatechange = null;
oDom.__loadDom__(oHttp.responseXML);
oDom.__checkForErrors__();
}
oDom.__changeReadyState__(oHttp.readyState);
};
}
oHttp.send(null);
if (!this.async) oDom.__loadDom__(oHttp.responseXML);
};
Node.prototype.getText = function () {
var sText = "";
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].hasChildNodes()) {
sText += this.getText();
} else {
sText += this.childNodes[i].nodeValue;
}
}
return sText;
};
Node.prototype.getXml = function () {
return (new XMLSerializer()).serializeToString(this, "text/xml") ||
(new XMLSerializer()).serializeToString(this);
};
//determine if the browser supports Dom LoadSave
if (zXml.settings.hasDomLS) {
//way to handle errors using DOM LS that mimicks IE's parseError object
oDomDocument.prototype.__checkForErrors__ = function (oError) {
if (!oError) return;
this.parseError.errorCode = -999999;
this.parseError.reason = oError.message;
this.parseError.url = oError.location.uri;
this.parseError.line = oError.location.lineNumber;
this.parseError.linepos = oError.location.columnNumber;
this.parseError.srcText = (oError.location.relatedNode)?"Around " + oError.location.relatedNode.nodeName:oError.type;
};
//loadXML() implementation by Jeremy McPeak
oDomDocument.prototype.loadXML = function (sXml) {
this.__initError__();
this.__changeReadyState__(1);
var oDom = this;
var iMode = document.implementation.MODE_SYNCHRONOUS;
//Create the parser in synchronous mode.
var oParser = document.implementation.createLSParser(iMode, null);
//Assign the error handler
oParser.domConfig.setParameter("error-handler",
function (oEx) {
oDom.__checkForErrors__(oEx);
oDom.__changeReadyState__(4);
}
);
//The LoadSave interface requires an LSInput object to load with parse().
//The stringData property is used.
var oInput = document.implementation.createLSInput();
oInput.stringData = sXml;
//Call parse() and send the resulting DOM to __loadDom__ to load it
//into this document.
try {
var oXmlDom = oParser.parse(oInput);
this.__loadDom__(oXmlDom);
this.__changeReadyState__(4);
} catch (e) {} //We don't want to do anything here. LSException objects suck for info.
};
} else {
//sorry opera,
if (!window.opera) {
//mozilla-specific way of handling errors
oDomDocument.prototype.__checkForErrors__ = function (oEx) {
if (this.documentElement.tagName == "parsererror") {
var reError = />([\s\S]*?)Location:([\s\S]*?)Line Number (\d+), Column (\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;
reError.test(this.xml);
this.parseError.errorCode = -999999;
this.parseError.reason = RegExp.$1;
this.parseError.url = RegExp.$2;
this.parseError.line = parseInt(RegExp.$3);
this.parseError.linepos = parseInt(RegExp.$4);
this.parseError.srcText = RegExp.$5;
}
};
}
//implementation of loadXML for DOMParser browsers
oDomDocument.prototype.loadXML = function (sXml) {
this.__initError__();
this.__changeReadyState__(1);
var oParser = new DOMParser();
var oXmlDom = null;
var bErrorChecked = false;
//some browsers throw an error if parsing fails
try {
oXmlDom = oParser.parseFromString(sXml, "text/xml");
this.__loadDom__(oXmlDom);
} catch (oEx) {
this.__checkForErrors__(oEx);
bErrorChecked = true;
}
if (!bErrorChecked) {
this.__checkForErrors__();
}
this.__changeReadyState__(4);
};
}
//add properties if supported
if (Node.prototype.__defineGetter__) {
//define xml property if not already defined
if (typeof Node.prototype.xml == "undefined") {
Node.prototype.__defineGetter__("xml", function () {
return this.getXml();
});
}
//add text property if not already defined
if (typeof Node.prototype.text == "undefined") {
Node.prototype.__defineGetter__("text", function () {
return this.getText();
});
}
}
}
/**
* Static class for handling XSLT transformations.
* @class
* @scope public
*/
function zXslt() {
}
/**
* Transforms an XML DOM to text using an XSLT DOM.
* @static
* @scope public
* @param oXml The XML DOM to transform.
* @param oXslt The XSLT DOM to use for the transformation.
* @return The transformed version of the string.
*/
zXslt.transformToText = function (oXml /*:XMLDocument*/, oXslt /*:XMLDocument*/)/*:String*/ {
if (zXml.settings.hasXSLTProcessor) {
var oProcessor = new XSLTProcessor();
oProcessor.importStylesheet(oXslt);
var oResultDom = oProcessor.transformToDocument(oXml);
var sResult = oResultDom.getXml();
if (sResult.indexOf("<transformiix:result") > -1) {
sResult = sResult.substring(sResult.indexOf(">") + 1,
sResult.lastIndexOf("<"));
}
return sResult;
} else if (zXml.settings.hasActiveX) {
return oXml.transformNode(oXslt);
} else {
throw new Error("No XSLT engine found.");
}
};
/**
* Static class for handling XPath evaluation.
* @class
* @scope public
*/
function zXPath() {
}
/**
* Selects the first node matching a given XPath expression.
* @static
* @scope public
* @param oRefNode The node from which to evaluate the expression.
* @param sXPath The XPath expression.
* @param oXmlNs An object containing the namespaces used in the expression. Optional.
* @return An XML node matching the expression or null if no matches found.
*/
zXPath.selectNodes = function (oRefNode /*:Node*/, sXPath /*:String*/, oXmlNs /*:Object*/) {
if (oRefNode.ownerDocument && oRefNode.ownerDocument.evaluate) {
oXmlNs = oXmlNs || {};
var nsResolver = function (sPrefix) {
return oXmlNs[sPrefix];
};
var oResult = oRefNode.ownerDocument.evaluate(sXPath, oRefNode, nsResolver,
XPathResult.ORDERED_NODE_ITERATOR_TYPE,
null);
var aNodes = new Array;
if (oResult != null) {
var oElement = oResult.iterateNext();
while(oElement) {
aNodes.push(oElement);
oElement = oResult.iterateNext();
}
}
return aNodes;
} else if (zXml.settings.hasActiveX) {
if (oXmlNs) {
var sXmlNs = "";
for (var sProp in oXmlNs) {
if (oXmlNs.hasOwnProperty(sProp)) {
sXmlNs += "xmlns:" + sProp + "=\'" + oXmlNs[sProp] + "\' ";
}
}
oRefNode.ownerDocument.setProperty("SelectionNamespaces", sXmlNs);
}
return oRefNode.selectNodes(sXPath);
} else {
throw new Error("No XPath engine found.");
}
};
/**
* Selects the first node matching a given XPath expression.
* @static
* @scope public
* @param oRefNode The node from which to evaluate the expression.
* @param sXPath The XPath expression.
* @param oXmlNs An object containing the namespaces used in the expression.
* @return An XML node matching the expression or null if no matches found.
*/
zXPath.selectSingleNode = function (oRefNode /*:Node*/, sXPath /*:String*/, oXmlNs /*:Object*/) {
if (oRefNode.ownerDocument && oRefNode.ownerDocument.evaluate) {
oXmlNs = oXmlNs || {};
var nsResolver = function (sPrefix) {
return oXmlNs[sPrefix];
};
var oResult = oRefNode.ownerDocument.evaluate(sXPath, oRefNode, nsResolver,
XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (oResult != null) {
return oResult.singleNodeValue;
} else {
return null;
}
} else if (zXml.settings.hasActiveX) {
if (oXmlNs) {
var sXmlNs = "";
for (var sProp in oXmlNs) {
if (oXmlNs.hasOwnProperty(sProp)) {
sXmlNs += "xmlns:" + sProp + "=\'" + oXmlNs[sProp] + "\' ";
}
}
oRefNode.ownerDocument.setProperty("SelectionNamespaces", sXmlNs);
}
return oRefNode.selectSingleNode(sXPath);
} else {
throw new Error("No XPath engine found.")
}
};
/**
* General purpose XML serializer.
* @class
*/
function zXMLSerializer() {
}
/**
* Serializes the given XML node into an XML string.
* @param oNode The XML node to serialize.
* @return An XML string.
*/
zXMLSerializer.prototype.serializeToString = function (oNode /*:Node*/)/*:String*/ {
var sXml = "";
switch (oNode.nodeType) {
case 1: //element
sXml = "<" + oNode.tagName;
for (var i=0; i < oNode.attributes.length; i++) {
sXml += " " + oNode.attributes[i].name + "=\"" + oNode.attributes[i].value + "\"";
}
sXml += ">";
for (var i=0; i < oNode.childNodes.length; i++){
sXml += this.serializeToString(oNode.childNodes[i]);
}
sXml += "</" + oNode.tagName + ">";
break;
case 3: //text node
sXml = oNode.nodeValue;
break;
case 4: //cdata
sXml = "<![CDATA[" + oNode.nodeValue + "]]>";
break;
case 7: //processing instruction
sXml = "<?" + oNode.nodevalue + "?>";
break;
case 8: //comment
sXml = "<!--" + oNode.nodevalue + "-->";
break;
case 9: //document
for (var i=0; i < oNode.childNodes.length; i++){
sXml += this.serializeToString(oNode.childNodes[i]);
}
break;
}
return sXml;
};
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="JSON-STRUTS2" extends="json-default">
<action name="userinfo" class="com.apache.struts.JSONWithStruts2" method="getData">
<result type="json"/>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>JSON</display-name>
<!-- BEGIN: copied from struts howto -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- END: copied from struts howto -->
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
<project name="JSON-STRUTS2" default="war" basedir=".">
<path id="classpath.path">
<pathelement location="${classes}"/>
<pathelement location="${lib}"/>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<tstamp/>
<property name="project" value="${ant.project.name}"/>
<property name="build" value="build"/>
<property name="src" value="src"/>
<property name="classes" value="${build}/classes"/>
<property name="lib" value="lib"/>
<property name="jsp" value="jsp"/>
<mkdir dir="${build}"/>
</target>
<target name="clean" depends="init">
<delete includeemptydirs="true">
<fileset dir="${build}" includes="**/*"/>
</delete>
</target>
<target name="compile" depends="init, clean">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" debuglevel="lines,source" debug="on" nowarn="on" fork="yes">
<classpath>
<path refid="classpath.path"/>
</classpath>
</javac>
</target>
<target name="war" depends="compile">
<copy todir="${classes}" file="config/struts.xml"/>
<!-- <copy todir="WEB-INF">
<fileset dir="${build}" includes="classes/**"/>
<fileset dir="." includes="lib/*"/>
</copy>
<jar destfile="${build}/${ant.project.name}.war">
<fileset dir="." includes="WEB-INF/**"/>
<fileset dir="." includes="jsp/**"/>
</jar>
-->
<war destfile="${build}/${ant.project.name}.war" webxml="WEB-INF/web.xml" followsymlinks="on">
<classes dir="${classes}"/>
<lib dir="${lib}"/>
<fileset dir="${basedir}" includes="jsp/**"/>
<fileset dir="${basedir}" includes="js/**"/>
</war>
</target>
<target name= "deploy" depends ="war">
<delete file="C:\tomcat-6.0.13\webapps\${ant.project.name}.war"/>
<delete dir="C:\tomcat-6.0.13\webapps\${ant.project.name}"/>
<copy toDir="C:\tomcat-6.0.13\webapps" file="${build}/${ant.project.name}.war" failonerror="false"/>
</target>
</project>
I copied two attachments here. First sample is mine. Second sample is done by my colleague Mr.Veeresh who is expert in JSON.