Struts2 Result 매개 변수 상세 정보

서버에 제출하는 처리는 일반적으로 두 단계로 나눌 수 있다. 첫 번째 단계는 서버 상태 조회 (조회 또는 데이터베이스 업데이트), 두 번째 단계는 사용자에게 되돌아갈 적당한 결과 페이지를 선택한다.
Struts2는 JSP, Free Marker, Velocity 등 다양한 종류의 결과를 지원합니다.
Struts2가 지원하는 다양한 유형의 반환 결과는 다음과 같습니다.
이름.
설명
Chain Result
Action 체인 작업
Dispatcher Result
페이지로 전환하기 위해 일반적으로 JSP 처리
FreeMarker Result
FreeMarker 템플릿 작업
HttpHeader Result
특수한 Http 동작을 제어하는 데 사용
Redirect Result
URL로 리디렉션
Redirect Action Result
Action 으로 리디렉션
Stream Result
일반적으로 파일 다운로드를 처리하는 데 사용되는 InputSream 객체를 브라우저에 보내기
Velocity Result
Velocity 템플릿 작업
XLS Result
XML/XLST 템플릿 작업
PlainText Result
원본 파일 내용(예: 파일 소스 코드) 표시
S2PLUGINS:Tiles Result
Tile 결합 사용
또한 제3자의 Result 유형은 JasperReports Plugin을 포함하여 JasperReport 유형의 보고서 출력을 처리하는 데 전문적으로 사용된다.
struts-default.xml 파일에 이미 모든 종류의 Result에 대한 정의가 있습니다.

<result-types>
<result-type name="chain"
class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher"
class="org.apache.struts2.dispatcher.ServletDispatcherResult"
default="true"/>
<result-type name="freemarker"
class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader"
class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect"
class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction"
class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream"
class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity"
class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt"
class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText"
class="org.apache.struts2.dispatcher.PlainTextResult" />
<!-- Deprecated name form scheduled for removal in Struts 2.1.0.
The camelCase versions are preferred. See ww-1707 -->
<result-type name="redirect-action"
class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="plaintext"
class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
상기 코드에서 알 수 있듯이 Result 형식을 지정하지 않을 때dispatcher 형식을 사용합니다.
Result 값을 정의합니다.

<result name="success" type="dispatcher">
<param name="location">/ThankYou.jsp</param>
</result>
type 기본값은dispatcher이기 때문에 정의할 필요가 없습니다. 또한name의 기본값은success이기 때문에 정의할 필요가 없습니다.
위의 코드는 다음과 같이 요약할 수 있습니다.

<result>
<param name="location">/ThankYou.jsp</param>

</result>
또한 location 매개 변수는 result 라벨 내부를 직접 마운트 해제할 수 있기 때문에 상기 코드의 가장 간단한 쓰기 방법은 다음과 같다.

<result>/ThankYou.jsp</result>
저희도 여러 가지 다른 Result를 정의할 수 있어요.

<action name="Hello">
<result>/hello/Result.jsp</result>
<result name="error">/hello/Error.jsp</result>
<result name="input">/hello/Input.jsp</result>
</action>
상기 코드의 의미는 이름이 Hello인 Action은 세 개의 반환 결과가 있고 모두 디스패치 형식(기본 형식)이다. 이 세 개의 반환 값의 이름은 각각success(기본값), error, input이고 대응하는 페이지의 경로는 각각/hello/Result이다.jsp,/hello/Error.jsp,/hello/Input.jsp.
때때로 우리는 전역적인 Result를 정의해야 한다. 이때 우리는 패키지 내부에서 전역적인 Result를 정의할 수 있다. 예를 들어

<global-results>
<result name="error">/Error.jsp</result>
<result name="invalid.token">/Error.jsp</result>
<result name="login" type="redirect-action">Logon!input</result>
</global-results>
동적 반환 결과
어떤 때는 Action이 완전하게 실행되었을 때만 어떤 결과를 되돌려야 하는지 알 수 있다. 이때 우리는 Action 내부에서 하나의 속성을 정의할 수 있다. 이 속성은 Action이 완전하게 실행된 후의 Result 값을 저장하는 데 사용된다. 예를 들어

private String nextAction;
public String getNextAction() {
 return nextAction;
}
strutx에서xml 프로필에서 ${nextAction}을 사용하여 Action의 속성을 인용할 수 있습니다. ${nextAction}이 표시하는 내용을 통해 동적으로 결과를 되돌려줍니다. 예를 들어 다음과 같습니다.

<action name="fragment" class="FragmentAction">
<result name="next" type="redirect-action">${nextAction}</result>
</action>
상술한 Action의execute 방법은next를 되돌릴 때nextAction의 속성에 따라 어떤 Action을 구체적으로 포지셔닝하는지 판단해야 한다.
다른 액션으로 전달하려면 type=chain을 설정하고 결과는shtml를 추가하지 않습니다
이상은 Struts2 Result 매개 변수에 대한 상세한 설명의 모든 내용입니다. 참고 부탁드리며 많은 응원 부탁드립니다.

좋은 웹페이지 즐겨찾기