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;
}
[b]问题补充:[/b]
Jsp中那样写!但我要的是这么拦截到Action中的Forward!能给些具体JAVA代码吗?
struts2不是有拦截器吗?也是AOP啊。例如方法过滤器
示范代码:
public class MyFilter extends MethodFilterInterceptor{
public String doIntercept(ActionInvocation invocation)throws Exception{
//MyAction为自定义的Action
MyAction atcion = (MyAction)invocation.getAction();
//.....
return "sucess";//在struts2,forward返回一个字符串即可
}
}
配置:
/page.jsp
execute
这样定义就可以了
在struts.xml中这样配置你的result就可以了:
actionName.action
补充:如果是带参数的话
actionName.action?var=${var}