电子通讯薄(MVC) :此示例基于MVC模式,包含四个界面:登入、添加数据、查询数据和显示所有数据,通过这个示例将会对Struts构架有进一步的了解
源代码在线查看: insertform.java
package addressbook.forms; import org.apache.struts.action.*; import javax.servlet.http.*; import addressbook.model.*; public class InsertForm extends ActionForm { private AddressBook addressBook=new AddressBook(); public void AddressBook(AddressBook addressBook) { this.addressBook=addressBook; } public AddressBook getAddressBook() { return this.addressBook; } public void setName(String name) { this.addressBook.setName(name); } public String getName() { return this.addressBook.getName(); } public void setPhone(String phone) { this.addressBook.setPhone(phone); } public String getPhone() { return this.addressBook.getPhone(); } public void setAddress(String address) { this.addressBook.setAddress(address); } public String getAddress() { return this.addressBook.getAddress(); } public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) { /**@todo: finish this method, this is just the skeleton.*/ return null; } public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) { this.addressBook=new AddressBook(); } }