<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ā)的事件和回寫(xiě)結果的處理方法。采用很巧妙的封裝方法實(shí)現了Struts的AJAX調用。當然Ajaxtags離實(shí)用階段還有相對長(cháng)的一段距離,但它提供了一種在現有的軟件架構上高效率開(kāi)發(fā)ajax應用程序的可行性方案。 目前buffalo主要有如下問(wèn)題:
a. JAVA Object的序列化邏輯與RPC的業(yè)務(wù)邏輯混在一起,不利于系統的擴展
b. buffalo只支持UTF-8編碼的XML,不支持GBK編碼的XML
c. buffalo可以調用服務(wù)的所有方法,可能會(huì )對服務(wù)器產(chǎn)生一定的安全隱患
//*********************************************
// 定義Pet(寵物)對象
//*********************************************
function Pet() {
//名稱(chēng)
this.name = null;
//顏色
this.color = null;
//獲取名稱(chēng)
this.getName = function() {
return this.name;
};
//設置名稱(chēng)
this.setName = function(newName) {
this.name = newName;
};
//獲取顏色
this.getColor = function() {
return this.color;
};
//設置顏色
this.setColor = function(newColor) {
this.color = newColor;
};
//定義一個(gè)需要實(shí)現的方法
this.getFood = null;
//獲取寵物的描述信息
this.toString = function() {
return "The pet is " + this.name +",it‘s "+this.color+",and it likes "+this.getFood()+".";
};
}
//*********************************************
// 定義Cat(貓)對象
//*********************************************
function Cat() {
//實(shí)現Pet中定義的getFood方法
this.getFood = function() {
return "fish";
};
}
//聲明Cat的原型,即Cat的父類(lèi)
Cat.prototype = new Pet;
多層次繼承
//*********************************************
// 定義PersianCat(波斯貓)對象
//*********************************************
function PersianCat() {
}
//聲明PersianCat的原型,即PersianCat的父類(lèi)
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() {
//名稱(chēng)
this.name = null;
//顏色
this.color = null;
//獲取名稱(chēng)
this.getName = function() {
return this.name;
};
//設置名稱(chēng)
this.setName = function(newName) {
this.name = newName;
};
//獲取顏色
this.getColor = function() {
return this.color;
};
//設置顏色
this.setColor = function(newColor) {
this.color = newColor;
};
//定義一個(gè)需要實(shí)現的方法
this.getFood = null;
//獲取寵物的描述信息
this.toString = function() {
return "The pet is " + this.name +",it‘s "+this.color+",and it likes "+this.getFood()+".";
};
}//*********************************************
// 定義Cat(貓)對象
//*********************************************
function Cat() {
//實(shí)現Pet中定義的getFood方法
this.getFood = function() {
return "fish";
};
}//聲明Cat的原型,即Cat的父類(lèi)
Cat.prototype = new Pet;//*********************************************
// 定義PersianCat(波斯貓)對象
//*********************************************
function PersianCat() {
}//聲明PersianCat的原型,即PersianCat的父類(lèi)
PersianCat.prototype = new Cat;//重載Pet的toString方法
PersianCat.prototype.toString = function() {
return "It‘s just a persian cat.";
};//*********************************************
// 定義Dog(狗)對象
//*********************************************
function Dog() {
//實(shí)現Pet中定義的getFood方法
this.getFood = function() {
return "bone";
};
}//聲明Dog的原型,即Dog的父類(lèi)
Dog.prototype = new Pet;
<script language="javascript" src="Pet.js" >
</ script >
< script language="javascript">
//定義一個(gè)Cat對象
var cat = new Cat();
cat.setName("MiMi");
cat.setColor("white");
//定義一個(gè)Dog對象
var dog = new Dog();
dog.setName("WangWang");
dog.setColor("yellow");
//定義一個(gè)PersianCat對象
var persianCat = new PersianCat();
//定義數組,保存上面的三個(gè)對象
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>
聯(lián)系客服