> Hello World !!!

     

@syaku

Struts2 Action 의 자료를 interceptor 로 넘겨주는 방법 : 스트럿츠2 , 액션 , 인터셉터


written by Seok Kyun. Choi. 최석균

"스트럿츠2 액션의 자료를 인터셉터 로 넘겨주는 방법"

액션에서 사용된 자료 인터셉터에 넘겨주는 방법을 공유하고자 한다.

소스가 몇줄되지 않아 어려운 점은 없으니 모르는 분들을 위해 팁을 준비한 것이다.


자료를 공유하기 위해 밸류스택을 사용한다.


// 액션


ActionContext context = ActionContext.getContext();

ValueStack valuestack = context.getValueStack();


Map stack = new HashMap();

stack.put("MID",MID);

stack.put("module_orl",module_orl);


valuestack.push(stack);



// 인터셉터


ActionContext context = invocation.getInvocationContext();

ValueStack valuestack = context.getValueStack();


String mid = (String) valuestack.findValue("MID");

String module_orl = (String) valuestack.findValue("module_orl");




[추가 내용] ModelDriven 인터셉터를 사용하면 위와같은 역활을 한다.


// 액션


액션에 <interceptor-ref name="modelDriven" /> 설정하고


액션 클래스에  implements ModelDriven  상속 받는 다.

  public Map stack = new HashMap();


  public void .......... {


    stack.put("MID",MID);

  }

  public Object getModel() {

    return stack;

  }


// 인터셉터


String mid = (String) valuestack.findValue("MID");


posted syaku blog

Syaku Blog by Seok Kyun. Choi. 최석균.

http://syaku.tistory.com