Struts2--注解配置
Action注解配置
使用方式如下:
@ParentPackage(value="struts-default")@Namespace(value="/test")@Result(name="success",value="/userSuc.jsp")@Results({ @Result(name="success",value="/userSuc.jsp",type=org.apache.struts2.dispatcher.ServletRedirectResult.class), @Result(name="input",value="/main.jsp",type=org.apache.struts2.dispatcher.ServletRedirectResult.class)})
<filter> <filter-name>struts</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>user.actions,other.actions</param-value> </init-param></filter>
public class TestAction extends ActionSupport { @Before public void doBefore(){ System.out.println("注解配置的方法在action执行之前调用"); } @After public void doAfter(){ System.out.println("注解配置的方法在action执行之后调用"); } @BeforeResult public void doBeforeResult(){ System.out.println("注解配置的方法在Result返回之前调用"); } …….}
<package name="test" extends="struts-default"> <interceptors> <interceptor name="annoInteceptor" class="action.TestAction"> ..... <interceptor-ref name="annoInteceptor"></interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </action> .......</package>