国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Struts的動(dòng)態(tài)表單的應(yīng)用

2019-11-17 06:25:49
字體:
供稿:網(wǎng)友

  Struts的動(dòng)態(tài)表單的應(yīng)用

假如你使用過struts先前的版本,你就會(huì)注重到你需要花費(fèi)大量的時(shí)候來寫ActionForm類文件,而這些類文件對(duì)于struts都是非常要害的(它充當(dāng)“View”的一部分),通常它的結(jié)構(gòu)就是bean PRoperties在加上一個(gè)validate方法(有時(shí)還有reset方法)。

隨著struts1.1版本的推出,開發(fā)員有了另外一種方法來完成前面的任務(wù):使用DynaBeans。DynaBeans動(dòng)態(tài)生成java Beans。這就意味著我們可以通過配置(通常利用xml

來生成formbean而不是在formbean中硬編碼。

為了了解DynaBeans(struts中為Dynaforms)是如何工做的,讓我們看一個(gè)簡單的表單,字段有:name,address,telephone等,下面的代碼為通常的寫法(沒有使用Dynaforms)。

article1.CustomerForm

package article1;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;
import javax.servlet.http.HttpServletRequest;

public class CustomerForm extends ActionForm {

protected boolean nullOrBlank (String str) {
return ((str == null) (str.length() == 0));
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (nullOrBlank(lastName)) {
errors.add("lastName",
new ActionError("article1.lastName.missing"));
}
if (nullOrBlank(firstName)) {
errors.add("firstName",
new ActionError("article1.firstName.missing"));
}
if (nullOrBlank(street)) {
errors.add("street",
new ActionError("article1.street.missing"));
}
if (nullOrBlank(city)) {
errors.add("city",
new ActionError("article1.city.missing"));
}
if (nullOrBlank(state)) {
errors.add("state",
new ActionError("article1.state.missing"));
}
if (nullOrBlank(postalCode)) {
errors.add("postalCode",
new ActionError("article1.postalCode.missing"));
}
if (nullOrBlank(phone)) {
errors.add("phone",
new ActionError("article1.phone.missing"));
}
return errors;
}

private String lastName;
private String firstName;
private String street;
private String city;
private String state;
private String postalCode;
private String phone;

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永胜县| 金寨县| 德惠市| 申扎县| 铜梁县| 贵阳市| 斗六市| 成武县| 萨嘎县| 乌拉特前旗| 信丰县| 綦江县| 荣昌县| 吴江市| 芦溪县| 康乐县| 耒阳市| 临潭县| 平遥县| 长丰县| 子长县| 商城县| 西宁市| 徐汇区| 周至县| 岱山县| 平江县| 崇信县| 永年县| 赤峰市| 永济市| 贵南县| 大渡口区| 赣榆县| 东港市| 安岳县| 行唐县| 汤原县| 临泉县| 娄烦县| 双江|