Struts 이용 중 Redirect 시 parameter 을 넘겨야 할 필요성이 있다.

struts 1.2 버전 밑에서는 아래와 같이 한다.

return new ActionForward("/index.do?param=value", true);

하지만 이 방법은 이동 URL을 JAVA 파일에 정의하게되어  struts의 struts-config.xml 설정파일과 별도로 관리해야 하는 단점이 있다.


그래서 struts 1.2 이상에서부터는 아래와 같은 방법을 제공한다.

ActionRedirect redirect = new ActionRedirect( mapping.findForward("success") );
redirect.addParameter("param", "123");
return redirect;

"success" 이름으로 struts-config.xml 에 정의된 URL에 param 이라는 parameter 정보를 붙여준다.

또한 1.2 이후 부터는 단순 jsp 이동 시 아래 방법은 이용 못하고, 
<action path="/index2" type="org.apache.struts.actions.ForwardAction" forward="/index.jsp" />

이 방법을 사용해야 된다.
<action path="/index" forward="/index.jsp" />

+ Recent posts