问题描述
Struts 1中我可以这样做!!! ModuleConfig config = (ModuleConfig) context.getAttribute("org.apache.struts.action.MODULE"); return HandlerUtil.getForward(method, config); public static String getForward(Method method, ModuleConfig config) { String actionName = getActionName(method); String forward = (actionName + "_" + method.getName()).toLowerCase(); if (config.findActionConfig("/" + actionName).findForwardConfig(forward) == null) { forward = DEFAULT_FORWARD; } return forward; } 问题补充:Jsp中那样写!但我要的是这么拦截到Action中的Forward!能给些具体JAVA代码吗?
解决方案
struts2不是有拦截器吗?也是AOP啊。例如方法过滤器示范代码:public class MyFilter extends MethodFilterInterceptor{public String doIntercept(ActionInvocation invocation)throws Exception{//MyAction为自定义的ActionMyAction atcion = (MyAction)invocation.getAction();//.....return "sucess";//在struts2,forward返回一个字符串即可}}配置:<interceptor name="myfilter" class="MyFilter"></interceptor><action name="myaction" class="MyAction"><return name="sucess">/page.jsp</return><interceptor-ref name="myfilter><param name="includeMethods">execute</param></interceptor-ref></action>
解决方案二:
补充:如果是带参数的话<result type="redirect">actionName.action?var=${var}</result>
解决方案三:
在struts.xml中这样配置你的result就可以了:<result type="redirect">actionName.action</result>
解决方案四:
<result type="redirect-action">这样定义就可以了