7. Using results
- Result는 Action의 결과에 따라 보여줍니다.(result가 없는 action은 없다)
- 우리가 필요한 대부분의 Result는 이미 WebWork에서 제공해 주고 있기 때문에 새로 Result를 만들 일은 없다.
7.1 Life after the action
7.1.1 A simple result
- 모든 result는 com.opensymphony.xwork.Result 인터페이스를 반드시 구현해야 한다.
package com.opensymphony.xwork;
public interface Result {
public void execute(ActionInvocation invocation) throws Exception;
}
7.1.2 Configuration a result
- result는 action과 interceptor처럼 xwork.xml에 설정한다.
- result는 package에 둘 수 있고 상속할 수 있다.
7.2 Common results
대부분 result는 다음의 3가지 type을 갖는다.
- dispatcher
- redirect
- chain: 다른 action을 호출
7.2.1 Dispatching to a page
Sevlet API 와 RequestDispatcher 를 이용하여 같은 HTTP request에서 다른 page(ex.JSP, servlet, and so on...)를 보여주는 것이 가능하다.
- dispatcher: webwork의 default result type

Configuring a dispatch result
- webwork-default.xml 의 webwork-default package에 이미 dispatcher result-type이 있어서 아무런 설정없이 dispatcher result을 사용한다.
<result-type
name="dispatcher"
class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult"
default="true"
/>
<result name="success">/hello.jsp</result>
<result name="success" type="dispatcher">
<param name="location">/hello.jsp</param>
</result>
Parsing varibles
- location parameter 외에 parse parameter를 지원한다.
/${LAYOUT_FTL}.jsp
와 같이 dispatcher result에 OGNL을 쓸 수 있고 action의 getter에 의해 상수로 대체된다.
Context matters
2개의 dispatcher result(include, forward)에는 약간의 차이가 있는데 Servlet 스펙때문이다.
- include

- forward

7.2.2 Redirecting to a page

Configuring redirect
- 다음은 webwork-default.xml 의 한 부분이다. dispatcher 처럼 이미 포함되어 있어서 그냥 쓰면 된다.
- 사용자 브라우져를 거져서 다른 페이지로 이동하는 Result이다.(HTTP 302 응답을 반환한다)
<result-type
name="redirect"
class="com.opensymphony.webwork.dispatcher.ServletRedirectResult"/>
Chaining to another action
- 내부적으로 다른 Action을 실행하는 Result이다.
- 동일 request, 동일 value stack을 사용한다.
- value stack에 있는 모든 속성을 실행하는 Action에 설정해 준다.

Configuring an action chain
- 다음은 webwork-default.xml 에 이미 정의되어 있다.
<result-type
name="chain"
class="com.opensymphony.webwork.dispatcher.ActionChainResult"/>
7.3 Other results
Velocity
FreeMarker
- 오픈소스 HTML 템플릿 엔진
- velocity의 대안
- jsp taglib를 지원한다.
- webwork 2.2 에서는 UI tag에서 이것을 사용한다.
- FreeMarker 매뉴얼
- FTL tag: <#>
JasperReports
PDF, XLS, CSV 등의 형식으로 결과를 보여주는 템플릿 엔진이다.
문서에 대하여