实现拦截器——自定义拦截器(下篇)
?
<global-results> <result name="error">页面</result></global-results><global-exception-mappings> <exception-mapping exception="异常类型" result="error"><global-exception-mappings>
?
<action name="index" name="code">package lele.struts2.interceptor;public interface MyModelDriven<T> { T getModel();}
?
?
package lele.struts2.interceptor;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;import com.opensymphony.xwork2.util.ValueStack;public class MyModelDrivenInterceptor extends AbstractInterceptor {@Overridepublic String intercept(ActionInvocation invocation) throws Exception {Object action = invocation.getAction();if (action instanceof MyModelDriven) {if (null != ((MyModelDriven) action).getModel()) {Object obj = ((MyModelDriven) action).getModel();ValueStack vs = invocation.getStack();vs.push(obj);}}return invocation.invoke();}}?
?
?
?? ? ? PS:大家可以联系我
Mail: wanglehappy9112@gmail.com
MSN:wang4717@live.cm
QQ: ?471776739
?
1 楼 隐藏起来 2010-11-07 用了拦截器,但是吧xxx.action?a=123