'스트러츠2'에 해당되는 글 1건

  1. 2011.01.21 struts2 interceptor

struts.xml

      <interceptor-ref name="prepare"/>             
      <interceptor-ref name="modelDriven"/>
      <interceptor-ref name="params"/>

prepare인터셉터 : Action에서 Preparable인터페이스를 사용해서 prepare()메소드를 구현하면
                           Action메소드를 호출하기전에 먼저 prepare()메소드를 수행한다.
  * vo객체생성

modelDriven인터셉터 : ModelDriven인터페이스를 구현한 액션클래스의 getModel()메소드를
                                 호출해서 getModel()메소드가 반환하는 객체의 프로퍼티를 밸류 스택에 저장한다.
                                 이 인터셉터는 모델이 널값이 아닌 경우에 스택에 저장한다.
  * form에서 넘어온 데이터를 스택에 저장

params인터셉터 : 모든 파라미터를 밸류 스택에 저장한다.
  * 스택에 있는 데이터를 vo에 넣어줌

Action.java 

 public class UserName implements Preparable, ModelDriven<TestVo>{
    // Preparable과 ModelDriven을 implements한 후
    private TestVo testVo;
    public TestVo getTestVo() {
      return testVo;
    }
    public void setTestVo(TestVo testVo) {
      this.testVo = testVo;
    }

    //Preparable 인터페이스에 반드시 구현해야하는 메소드
    public void prepare(){
      // 여기에 사용자가 폼객체로 사용할 객체 생성
      testVo = new TestVo(); 
    }
    public TestVo getModel(){
      //프로퍼티를 밸류 스택에 저장
      return testVo
    }
    public String execute()  throws Exception{
      return "success";
    }
}

Posted by 미스터네오
,