

public class registForm extends ActionForm{
//所有属性都为私有的
private static final long serialVersionUID = 1L;
private String userName=null;
private String userPassword=null;
private String userPassword2=null;
private String phoneNo=null;
private String email=null;
public registForm(){
}
//以下都为部分属性的SET及GET方法
public void setUserPassword(String userPassword){
this.userPassword=userPassword;
}
public void setUserPassword2(String userPassword2){
this.userPassword2=userPassword2;
}
public String getUserPassword2(){
return userPassword2;
}
public void setEmail(String email){
this.email=email;
}
public String getEmail(){
return email;
}
//带全部属性的构造方法
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.userName=null;
this.userPassword=null;
this.userPassword2=null;
this.phoneNo=null;
this.email=null;
}
//如果一个Form想继承ActionForm必顺实现validate方法
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
/判断用户名,密码,二次输入的密码,邮箱只要有一个为空就跳转到错误页面,
//给出错误信息
if (userName==null || userPassword==null || userPassword2==null
|| phoneNo==null || email==null){
errors.add(ActionErrors.GLOBAL_MESSAGE,
new ActionMessage(""));
}
(3)ActionForm Bean的属性均为私有属性,其对应的有一对get()和set()方法;
(4)validate()方法在此userForm中没有任何验证,因为对应此JSP的表单中所有的数据都是让用户选择输入的,一般不会有灾难性的错误;
(5)视图层的界面
图 7是系统主登录的界面,图 8是站点管理主页面系统的界面风格是统一的。
图 7 登录界面
Fig 7 Login Interface
图 8 站点信息管理主界面
Fig 8 Station Information Admin Interface
4.3.2 控制层的实现
控制层主要介绍一下Action类,它是控制用户请求和业务逻辑的桥梁。所有控制层类要继承这个Action类,供ActionServlet所驱动。Action类的职责:调用业务逻辑方法将控制权返回给ActionServlet并且提供相关的路由信息。具体的Action类都是按以下步骤来开发的:首先,继承Action类。接着,覆盖 execute(...)方法。然后,返回ActionForward对象(提供决策信息给ActionServlet选择适当的视图响应用户)。最后,在struts-config.xml中配置。配置时都是按照如代码来配置的,
<action-mappings>
<action input="/index.jsp" :ActionForm验证失败的跳转页面
name="aForm" :与Action对应的FormBean对象
path="/myAction" :请求URI(/myAction.do) 转贴于 酷文网-论文下载中心 http://www.coolwen.net