TestAction.java:
public class TestAction extends ActionSupport{
@Autowired
private UserService userService;
@Action(value="/tm", interceptorRefs={@InterceptorRef("basicStack"),}, results={@Result(name="success",location="/a.jsp")}) public String testMethod(@Para("user")User user,@Para("a")String[] a) throws Exception{ System.out.println("------invoke testMethod-----"); if (user != null){ System.out.println("user name is " + user.getName()); } return "success"; }
}
TestUnknownHandler.java:
public class TestUnknownHandler implements UnknownHandler{
Logger logger = Logger.getLogger(TestUnknownHandler.class);
ActionMethodParameterConverter actionMethodParameterConverter;
@Inject
public void setActionMethodParameterConverter(ActionMethodParameterConverter actionMethodParameterConverter){
this.actionMethodParameterConverter = actionMethodParameterConverter;
}
public ActionConfig handleUnknownAction(String namespace, String actionName)
throws XWorkException {
// TODO Auto-generated method stub
return null;
}
public Object handleUnknownActionMethod(Object action, String methodName)
throws NoSuchMethodException {
//ActionContext ac = ActionContext.getContext();
logger.info(methodName + " - test unknown method ok ");
Object resultName = null;
try{
resultName = actionMethodParameterConverter.InvokeMethod(action, methodName);
logger.info(methodName + " result name is " + resultName);
}catch (Exception e){
e.printStackTrace();
}
// TODO Auto-generated method stub
return resultName;
}
public Result handleUnknownResult(ActionContext actionContext,
String actionName, ActionConfig actionConfig, String resultCode)
throws XWorkException {
// TODO Auto-generated method stub
return null;
}
}
Para.java:
@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Para {
String[] value();
}
struts.xml:
<struts>
<bean type="com.opensymphony.xwork2.UnknownHandler" name="default" class="com.xeehoo.annotation.TestUnknownHandler"/>
<bean type="com.xeehoo.struts.converter.ActionMethodParameterConverter" name="default" class="com.xeehoo.struts.converter.ActionMethodParameterConverter"/>