<html:form action="example1" ajaxRef="example1"> First Name: <html:text property="firstName" size="25" value="Frank" /> <br> Last Name: <html:text property="lastName" size="25" value="Zammetti" /> <br> <html:button property="button" value="Click to do Ajax!" ajaxRef="button" /></html:form>Result:<br><span id="example1_resultLayer"> </span>
注意<!DOCTYPE ajaxConfig PUBLIC "ajaxConfig" "ajaxConfig"><ajaxConfig> <!-- Define a custom request handler that generates XML for example 2 --> <handler name="CustomXMLGenerator" type="request"> <function>customGenerateXML</function> <location>customXMLGenerator.js</location> </handler> <!-- Configuration for example 1 --> <form ajaxRef="example1"> <element ajaxRef="button"> <event type="onclick"> <requestHandler type="std:QueryString"> <target>example1.do</target> <parameter>firstName=firstName,lastName=lastName</parameter> </requestHandler> <responseHandler type="std:InnerHTML"> <parameter>example1_resultLayer</parameter> </responseHandler> </event> </element> </form></ajaxConfig>
在配置文件中定義了該表單的屬性,以及按鈕觸發(fā)的事件和回寫結(jié)果的處理方法。采用很巧妙的封裝方法實現(xiàn)了Struts的AJAX調(diào)用。當(dāng)然Ajaxtags離實用階段還有相對長的一段距離,但它提供了一種在現(xiàn)有的軟件架構(gòu)上高效率開發(fā)ajax應(yīng)用程序的可行性方案。 目前buffalo主要有如下問題:
a. JAVA Object的序列化邏輯與RPC的業(yè)務(wù)邏輯混在一起,不利于系統(tǒng)的擴展
b. buffalo只支持UTF-8編碼的XML,不支持GBK編碼的XML
c. buffalo可以調(diào)用服務(wù)的所有方法,可能會對服務(wù)器產(chǎn)生一定的安全隱患
//*********************************************
// 定義Pet(寵物)對象
//*********************************************
function Pet() {
//名稱
this.name = null;
//顏色
this.color = null;
//獲取名稱
this.getName = function() {
return this.name;
};
//設(shè)置名稱
this.setName = function(newName) {
this.name = newName;
};
//獲取顏色
this.getColor = function() {
return this.color;
};
//設(shè)置顏色
this.setColor = function(newColor) {
this.color = newColor;
};
//定義一個需要實現(xiàn)的方法
this.getFood = null;
//獲取寵物的描述信息
this.toString = function() {
return "The pet is " + this.name +",it‘s "+this.color+",and it likes "+this.getFood()+".";
};
}
//*********************************************
// 定義Cat(貓)對象
//*********************************************
function Cat() {
//實現(xiàn)Pet中定義的getFood方法
this.getFood = function() {
return "fish";
};
}
//聲明Cat的原型,即Cat的父類
Cat.prototype = new Pet;
多層次繼承
//*********************************************
// 定義PersianCat(波斯貓)對象
//*********************************************
function PersianCat() {
}
//聲明PersianCat的原型,即PersianCat的父類
PersianCat.prototype = new Cat;
3.3. 重載(override)與多態(tài)(Polymorphism)
//重載Pet的toString方法
PersianCat.prototype.toString = function() {
return "It‘s just a persian cat.";
};
//*********************************************
// 定義Pet(寵物)對象
//*********************************************
function Pet() {
//名稱
this.name = null;
//顏色
this.color = null;
//獲取名稱
this.getName = function() {
return this.name;
};
//設(shè)置名稱
this.setName = function(newName) {
this.name = newName;
};
//獲取顏色
this.getColor = function() {
return this.color;
};
//設(shè)置顏色
this.setColor = function(newColor) {
this.color = newColor;
};
//定義一個需要實現(xiàn)的方法
this.getFood = null;
//獲取寵物的描述信息
this.toString = function() {
return "The pet is " + this.name +",it‘s "+this.color+",and it likes "+this.getFood()+".";
};
}//*********************************************
// 定義Cat(貓)對象
//*********************************************
function Cat() {
//實現(xiàn)Pet中定義的getFood方法
this.getFood = function() {
return "fish";
};
}//聲明Cat的原型,即Cat的父類
Cat.prototype = new Pet;//*********************************************
// 定義PersianCat(波斯貓)對象
//*********************************************
function PersianCat() {
}//聲明PersianCat的原型,即PersianCat的父類
PersianCat.prototype = new Cat;//重載Pet的toString方法
PersianCat.prototype.toString = function() {
return "It‘s just a persian cat.";
};//*********************************************
// 定義Dog(狗)對象
//*********************************************
function Dog() {
//實現(xiàn)Pet中定義的getFood方法
this.getFood = function() {
return "bone";
};
}//聲明Dog的原型,即Dog的父類
Dog.prototype = new Pet;
<script language="javascript" src="Pet.js" >
</ script >
< script language="javascript">
//定義一個Cat對象
var cat = new Cat();
cat.setName("MiMi");
cat.setColor("white");
//定義一個Dog對象
var dog = new Dog();
dog.setName("WangWang");
dog.setColor("yellow");
//定義一個PersianCat對象
var persianCat = new PersianCat();
//定義數(shù)組,保存上面的三個對象
var pets = new Array(3);
pets[0] = cat;
pets[1] = dog;
pets[2] = persianCat;
//測試程序
for(var i=0,size=pets.length;i<size;i++) {
alert(pets[i].toString());
}
</script>