서버에 제출 된 처리는 일반적으로 두 단계로 나눌 수 있습니다. 첫 번째 단계는 서버 상태 (쿼리 또는 데이터베이스 업데이트)를 쿼리하고 두 번째 단계는 적절한 결과 페이지를 선택하고 사용자에게 반환합니다 (여기에서 논의 될 결과의 내용).
Struts2는 다양한 종류의 반환 결과를 지원하며, 일반적인 결과는 JSP, 프리 마커, 속도 등을 포함합니다.
Struts2에서 지원하는 다양한 유형의 반환 결과는 다음과 같습니다.
| 이름 | 설명 |
|---|---|
| 체인 결과 | 액션 체인을 처리하는 데 사용됩니다 |
| 디스패처 결과 | 페이지로 돌아가서 일반적으로 JSP를 처리합니다 |
| 프리 마커 결과 | 프리 마커 템플릿을 처리합니다 |
| httpheader 결과 | 특별한 HTTP 동작을 제어하는 데 사용됩니다 |
| 결과를 리디렉션합니다 | URL로 리디렉션하십시오 |
| 작업 결과를 리디렉션합니다 | 행동으로 리디렉션하십시오 |
| 스트림 결과 | InputSReam 객체를 브라우저로 보내는데, 일반적으로 파일 다운로드를 처리하는 데 사용됩니다. |
| 속도 결과 | 속도 템플릿을 처리합니다 |
| XLS 결과 | XML/XLST 템플릿을 프로세스하십시오 |
| 일반 텍스트 결과 | 파일 소스 코드와 같은 원본 파일 컨텐츠를 표시합니다 |
| S2Plugins : 타일 결과 | 타일과 함께 사용하십시오 |
또한 타사 결과 유형에는 JasperReport 유형의 보고서 출력을 처리하는 데 특별히 사용되는 JasperReports 플러그인도 포함됩니다.
struts-default.xml 파일에는 모든 유형의 결과에 대한 정의가 이미 있습니다.
<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 이름 = "Freemarker"class = "org.apache.struts2.views.freemarker.freemarkerresult"/> <result-type name = "httpheader"class = "org.apache.structs2.dispatcher.httpheaderresult"/> <result-type 이름 = "REDIRECT"class = "org.apache.structs2.dispatcher.servletredirectresult"/> <result-type name = "redirectaction"class = "org.apache.structs2.dispatcher.servretredifectresult"/> <result-type 이름 = "stream"class = "org.apache.structs2.dispatcher.streamresult"/> <result-type name = "velocity"class = "org.apache.struts2.dispatcher.velocityResult"/> <result-type 이름 = "xslt"class = "org.apache.struts2.views.xslt.xsltresult" /> <result-type name = "plaintext"class = "org.apache.struts2.dispatcher.plaintextresult" /> <!-Struts에서의 제거로 예정된 예약. ww-1707-> <result-type name = "redirect-Action"class = "org.apache.structs2.dispatcher.servletActionRedifectresult"/> <result-type name = "plaintext"class = "org.apache.struts2.dispatcher.plaintextresult"/> </gougStypes>
위의 코드에서 결과 유형이 지정되지 않으면 사용됩니다.
결과 값을 정의하고
<result name = "success"type = "dispatcher"> <param name = "location">/thankyou.jsp </param> </result>
유형의 기본값은 디스패처이므로 여기에서 정의 할 필요가 없습니다. 또한 이름의 기본값은 성공이므로 여기에서 정의 할 필요가 없습니다.
위의 코드는 다음과 같이 축약 할 수 있습니다.
<결과> <param name = "location">/thankyou.jsp </param> </result>
또한 위치 매개 변수는 결과 태그에서 직접 제거 할 수 있으므로 위의 코드를 작성하는 가장 간단한 방법은 다음과 같습니다.
<결과>/thankyou.jsp </result>
여러 가지 다른 결과를 정의 할 수도 있습니다
<action name = "hello"> <cults> /hello/result.jsp </result> <result name = "error">/hello/error.jsp </result> <result name = "input">/hello/input.jsp </action> </action>
위의 코드의 의미는 Hello라는 이름의 동작에 3 개의 반환이 있으며 모두 디스패처 유형 (기본 유형)이라는 것입니다. 이 세 가지 반환 값의 이름은 성공 (기본값), 오류 및 입력입니다. 해당 페이지 경로는 /hello/result.jsp, /hello/error.jsp 및 /hello/input.jsp입니다.
때로는 글로벌 결과가 정의되어야합니다. 현재 패키지 내부의 글로벌 결과를 정의 할 수 있습니다.
<Global-Results> <result name = "error">/error.jsp </result> <result name = "invalid.token">/error.jsp </result> <result name = "login"type = "Redirect-Action"> 로그온! 입력 </global-results>
동적으로 결과를 반환합니다
때로는 작업이 완전한 BI를 실행할 때 반환 할 결과 만 알고 있습니다. 현재 작업 내부의 속성을 정의 할 수 있으며, 이는 작업이 완전한 BI를 실행 한 후 결과 값을 저장하는 데 사용됩니다.
개인 문자열 nextAction; public String getNextAction () {return nextAction;} strutx.xml configuration 파일에서 $ {nextAction}을 사용하여 작업의 속성을 참조하고 $ {nextAction}으로 표시된 컨텐츠를 통해 결과를 동적으로 반환 할 수 있습니다.
<action name = "fragment"> <result name = "next"type = "redirect-Action"> $ {nextAction} </result> </action> 위의 조치의 실행 방법이 다음에 반환 될 때 다음 Actions의 속성에 따라 어떤 동작이 있는지 결정해야합니다.
다른 작업으로 전달하려면 Type = Chain을 설정할 수 있으며 결과는 SHTML에 추가되지 않습니다.
위의 내용은 Struts2 결과 매개 변수에 대한 자세한 설명입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.