`
ssydxa219
  • 浏览: 622290 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

annotationWorkflow

 
阅读更多

首先配置struts.xml

<package name="default" namespace="/" extends="struts-default">
 <interceptors>
  <!-- 定义拦截器  name:拦截器名称 class:拦截器类路径 -->
  <interceptor name="annotationWorkflow"
   class="com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor" />
  <!-- 定义拦截器栈 -->
  <interceptor-stack name="mystack">
   <interceptor-ref name="annotationWorkflow" />
   <!-- 导入默认拦截器配置,不然无法取到值 -->
   <interceptor-ref name="defaultStack"/>
  </interceptor-stack>
 </interceptors>

 <!-- 将上述mystack拦截器栈设定为默认拦截器 -->
 <default-interceptor-ref name="mystack" />
</package>

新建CommonAction.java

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.annotations.After;
import com.opensymphony.xwork2.interceptor.annotations.Before;
import com.opensymphony.xwork2.interceptor.annotations.BeforeResult;

@Controller
public abstract class CommonAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {

    private static final long serialVersionUID = 4645378216719871106L;

    private Map<String, Object> sessionMap;

    private HttpServletRequest request;

    private HttpServletResponse response;

    //    protected Log log = LogFactory.getLog(this.getClass());
    protected Logger log = Logger.getLogger(this.getClass());

    @Before
    public void beforeMethod() {
        log.debug("●●before: - " + this.getClass().getName());
    }

    @BeforeResult
    public void beforeResultMethod() {
    }

    @After
    public void afterMethod() {
        ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
        log.debug("●●after: - " + this.getClass().getName() + " Result(" + invocation.getResultCode() + ")");
    }

    public void setSession(Map<String, Object> session) {
        this.sessionMap = session;
    }

    public Map<String, Object> getSession() {
        return sessionMap;
    }

    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setServletResponse(HttpServletResponse response) {
        this.response = response;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

然后修改PagingSampleAction.java

public class PagingSampleAction extends CommonAction implements ModelDriven<PagingSampleModel> {

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics