为了应付目前已开发大量的一些action的现有情况,同时也要解决以前工作不要去改动,又实现一些新功能, 查阅了一下资料。
基础思路如下:
?
在现有已方平台基础上的最基础的baseAction中加入基础方法,同时在全局继承的基础package,加入基础result
类型为“重定向”。返回值由基础action的变量动态生成。然后基于这些,就可以实现很灵活的操作,又不需要去重构旧代码
?
?
<package name="mydefault" extends="webwork-default">
<interceptors>
<interceptor-stack name="coralStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servlet-config"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="model-driven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="static-params"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">delete,edit,execute,list,selectlist</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">delete,edit,execute,list,selectlist</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="coralStack" />
<global-results>
<result name="error">/errors/error.jsp</result>
<!-- 全局返回的 -->
<result name="_toPage" type="redirect-action">${_toPageUrl}</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Throwable"/>
</global-exception-mappings>
</package>
?
?
?
/**
* 最基础的一个Controller,供继承
*
*/
abstract public class BaseAction extends ActionSupport{
/**
* 返回名
*/
protected static final String RESULT_TOPAGE = "_toPage";
private String _toPageUrl;
public String get_toPageUrl() {
return _toPageUrl;
}
public void set_toPageUrl(String pageUrl) {
_toPageUrl = pageUrl;
}
/**
* 跳转的基础方法,在公共配置上也对应的配置上了公共返回名
* @return
*/
public String toPageUrl(){
//测试 ../这个操作非常有用,因为webwork result中是相对路径,通过..可以调整路径,实现访问另一个模块
//this._toPageUrl = "../admin/resourceIndex.do?flag=1.00";
return RESULT_TOPAGE;
}
?
?
?