struts2 以注解的形式实现拦截器

package com.example.struts.action;

import java.util.Map;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.annotations.*;

public class LoginAction extends ActionSupport {
	private String username;
	@Before
	public void myBefore() {
		System.out.println("调用myBefore方法");
//		return LOGIN;
	}
	@After
	public void myAfter() throws InterruptedException {
		Thread.sleep(5000);
		System.out.println("----调用myAfter方法");
	}
	@BeforeResult
	public void myBeforeResult() {
		System.out.println("----调用myBeforeResult方法");
	}
	public String execute() throws Exception {
		System.out.println("调用execute方法");
		return SUCCESS;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		System.out.println("---调用set方法" + username);
		this.username = username;
	}



}

 

	<package name="ano" extends="struts-default">
		<interceptors>
			<interceptor name="anno"				class="com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor">
			</interceptor>
			<interceptor-stack name="annoStack">
				<interceptor-ref name="anno"></interceptor-ref>
				<interceptor-ref name="defaultStack"></interceptor-ref>
			</interceptor-stack>
		</interceptors>
		<action name="login" class="com.example.struts.action.LoginAction">
			<result name="success">/success.jsp</result>
			<result name="login">/login.jsp</result>
			<interceptor-ref name="annoStack"></interceptor-ref>
		</action>
		<action name="index">
			<result>/login.jsp</result>
		</action>
	</package>

 

你可能感兴趣的:(thread,jsp,struts)