
对应的时序图


public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Was this transaction cancelled?
if (isCancelled(request)) {
if (log.isInfoEnabled()) {
log.info(
" "
+ mapping.getAttribute()
+ " - Registration transaction was cancelled");
}
removeFormBean(mapping, request);
return (mapping.findForward("success"));
}
return mapping.findForward("success");
}
上面为何不直接在Action的方法中直接返回视图页面。而是把success对应的index.jsp放到配置文件中
实现的是解耦。在源代码中不能看到跳转的页面具体是什么了。
对应着struts-config中的
<!-- Registration Actions -->
<action path="/registration" forward="/registration.jsp" />
<action path="/registration-submit"
type="org.apache.struts.webapp.validator.RegistrationAction"
name="registrationForm"
scope="request"
validate="true"
cancellable="true"
input="input">
<forward name="input" path="/registration.do" />
<forward name="success" path="/index.jsp" />
</action>
扩展: http://liuxi1024.iteye.com/blog/1113398
本文探讨了Struts框架中如何通过配置文件实现视图层与业务逻辑层的解耦,详细解释了为何不在Action中直接返回视图,而是利用配置文件定义视图路径的方法。
194

被折叠的 条评论
为什么被折叠?



