[Struts] Action 에서 포워딩 시 parameter 넘기는 법

|


struts-config.xml에서의 설정으로는 동적으로 바뀌는 파라메터를 넘겨줄 수 없다.

그래서, 액션 클래스에서의 특별한 처리를 요구하는 데, 다음중 한 방법을 사용하면 된다.


  1.  ActionFoward 객체 직접 생성

    다음과 같이 ActionForward객체를 생성하여 리턴한다.
    return new ActionForward("/index.html?param=" + paramValue, true);

    파라메터가 많을 경우 코드가 지저분해지고 번거러울 수 있다.


  2. ActionMapping객체를 통한 ActionFoward객체 생성

    대부분의 경우 이같은 방법으로 포워드시킨다.

    excute() 메소드에서 전달 받은 ActionMapping 객체를 이용한다.
    ActionForward forward = mapping.findForward("success");
    ActionForward redirect

    = new ActionForward(forward.getName(), forward.getPath()
    + "?param=" + paramValue, true );

    return redirect;


  3. ActionRedirect 클래스 활용

    org.apache.struts.action.ActionRedirect 클래스를 import시켜서 사용한다.
    ActionRedirect redirect = new ActionRedirect( mapping.findForward("success") );
      redirect.addParameter("param", paramValue);
    return redirect;
    * 주의 : 이 방법은 struts 1.2.7 버전 부터 가능하다.



이 글은 스프링노트에서 작성되었습니다.

And