我们知道,所有的业务流程经过action后都需要转向到一个视图来呈现action的处理情况,在webwork中,这种被转向的页面大概分为如下几个类型(借用Action的注释说明如下):
public static final String SUCCESS = "success";
The action execution was successful. Show result view to the end user
public static final String NONE = "none";
The action execution was successful but do not show a view. This is useful for actions that are handling the view in another fashion like redirect.
public static final String ERROR = "error";
The action execution was a failure.Show an error view, possibly asking the user to retry entering data.
public static final String INPUT = "input";
The action execution require more input in order to succeed. This result is typically used if a form handling action has been executed so as to provide defaults for a form. The form associated with the handler should be shown to the end user. This result is also used if the given input params are invalid, meaning the user should try providing input again.
public static final String LOGIN = "login";
The action could not execute, since the user most was not logged in. The login view should be shown.
知道了上面这点以后我们再来看在action中如何进行配置:
- <result>/WEB-INF/pages/home.jspresult> <result name="error">/WEB-INF/pages/error.jspresult>
上面我们为一个action配置了一个SUCCESS,也就是没有名字的那个/WEB-INF/home.jsp和一个error.这样我们就可以在action中使用这两个流程了,如下(action的execute中的代码片段):
if(!StringUtils.isEmpty(errorFlag[0])){
return ERROR;
}
return SUCCESS;
如果errorFlag[0]为空则转发到error对应的页面,否则转发到成功页面,至于如何得到errorFlag[0]以后继续…………