블로그 이미지
헤이장

Notice

Recent Post

Recent Comment

Recent Trackback

calendar

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
  • total
  • today
  • yesterday
2009. 7. 27. 20:21 Web/Framework


<select id="getCategory_No" resultClass="vo.Category">
        select * from category where no = #value#
</select>

<select id="getCategory_No" parameterClass="int" resultClass="vo.Category">
        select * from category where no = #value#
</select>

두가지 경우는 동일한 결과를 보인다
parameterClass 가 VO 객체일 경우에도 동일하다
실제로 ibatis 교재에는 parameterClass 로 xml 을 받는 경우를 제외하고 대부분 parameterClass 를 선언하지 않고 있다

※ parameterClass 에 선언을 하지 않으면 - 어떤 파라메터도 전달이 된다
※ parameterClass 에 선언을 하면 - 그 자료형이 아니면 SQL예외처리가 발생한다

 parameterClass 를 선언해 주는 것이 잘못된 자료형이 전달되는 것을 미리 막아주는 것 같다

posted by 헤이장
2009. 7. 27. 20:19 Web/Framework

액션클래스가 실행되기전에 가로채서 어떤 일을 수행하는 인터셉터

우선 보면


<action name="chkLogin" class="action.CheckLoginAction">

            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="prepare"/>
            <interceptor-ref name="modelDriven"/>
            <interceptor-ref name="params"/>
            <result>main.jsp</result>
</action>


public class CheckLoginAction implements Preparable, ModelDriven<Member_Hanbit>, SessionAware {
...  생략 ...
}


모든 인터셉터는 정상적으로 작동한다.
 

그렇다면 이렇게 하면?


<action name="chkLogin" class="action.CheckLoginAction">
            <result>main.jsp</result>
</action>

public class CheckLoginAction implements Preparable, ModelDriven<Member_Hanbit>, SessionAware {
             ...  생략 ...
}

이건 또 뭔가...?
액션 클래스에 구현된 모든 인터셉터가 똑같이 정상 작동한다. 세션 조차도...
params 를 안 써도 파라메터도 받아진다


그럼 이건???


<action name="chkLogin" class="action.CheckLoginAction"> 
            <interceptor-ref name="params"/>
            <result>main.jsp</result>
</action>

public class CheckLoginAction implements Preparable, ModelDriven<Member_Hanbit>, SessionAware {
                ...  생략 ...
}

다른 인터셉터는 작동하지 않고 파라메터 인자만 받아진다....
(물론 객체가 없기때문에 위의 경우는 임시로 바로 받을 변수를 선언해주어야한다) 

※ struts.xml 에서 액션을 선언 할 경우
    인터셉터를 하나도 선언하지 않으면 알아서 구현된 모든 인터셉터를 실행해준다
    하지만.. 단 하나의 인터셉터라도 선언하게 된다면
    인터셉터의 자동 실행은 모두 사라지고 선언된 인터셉터만 실행된다 

    그렇다면 인터셉터는 귀찮게 선언할 필요가 없나 하면 그건 아닌거 같다 

만약 다른 모든 인터셉터가 실행되기 전에 prepare 에서도 전달된 파라메터 값이 필요할 때..


<action name="chkLogin" class="action.CheckLoginAction">
            <interceptor-ref name="params"/>
            <interceptor-ref name="prepare"/>
            <interceptor-ref name="modelDriven"/>
            <interceptor-ref name="params"/>
            <result>main.jsp</result>
</action>

이렇게 params 를 두번 선언해야 할 경우가 있다. // 스트럿츠2 프로그래밍 - 가메출판사 106 페이지 참고

 이럴때는 자동으로 실행되는 것으론 첫번째 params 가 실행되지 않는다 

※ 그러므로 가능하다면 모든 인터셉터를 선언해주는 것이 가장 좋을 것 같다
    꼭 액션클래스를 안봐도 사용된 인터셉터를 알 수 있게 가독성을 위해서도.

posted by 헤이장
2009. 7. 27. 13:13 Web/Framework

사용 클래스 : com.opensymphony.xwork2.ActionChainResult

두 개의 다른 액션에서 처음 액션의 프라퍼티를 다음 액션에 세팅하고 싶을때 chain 인터셉터를 이용한다 

예를 들어 회원등록 액션과 로그인 액션이 있는데
회원등록 후 그 정보로 이어서 바로 로그인으로 진행되게 한다

 RegisterUser.java

 public class RegisterUser implements Action { 

     private String userId;
     private String password;
     private String message; 

     public String execute() throws Exception {
          // 비지니스 로직 생략
          return SUCCESS;
     }
     // getter, setter 생략
}


 LoginAction.java

 public class LoginAction implements Action {
     private String userId;
     private String password;
     private String message;
     public String execute() throws Exception {
          // 비지니스 로직 생략
          return SUCCESS;
     }
     //getter, setter 생략
}

 struts.xml

 <package name="ex" extends="struts-default">
     <action name="registerAndLogin" class="action.RegisterUser">
          <interceptor-ref name="params"/>
          <result name="success" type="chain">login</result>
     </action>

     <action name="login" class="action.LoginAction">
          <interceptor-ref name="chain"/>
          <interceptor-ref name="params"/>
     <result name="success" type="dispatcher">/result.jsp</result>
     </action>
</package>

posted by 헤이장
2009. 7. 27. 13:10 Web/Framework

- struts.xml - 

<action name="*/*" class="action.{1}Action" method="{2}">
     <result name="success">{2}.jsp</result>
</action>

첫번째 * 은 {1} 에, 두번째 * 은 {2} 에 해당된다

http://localhost:8084/Struts2/First/second.action

이 경우에
action/FirstAction.java 에서 second() 를 실행하고
second.jsp 로 결과를 보낸다

posted by 헤이장