चल रहे हैं पहली नज़र में मैं निश्चित रूप से सहमत होंगे। जो आप दिखाते हैं वह सहज नहीं दिखता है। लेकिन वास्तव में क्या हो रहा है वह मूल्य स्टैक से अनुरोध ऑब्जेक्ट तक पहुंच प्राप्त कर रहा है, वास्तव में इसके विपरीत नहीं। आप वैल्यू स्टैक में पेज कॉन्टेक्स्ट से शुरू करते हैं, और आप अभी भी अंत में कुछ के साथ काम कर रहे हैं, जिसके पास अभी भी वैल्यू स्टैक तक पहुंच है (इसके पास भी अनुरोध तक पहुंच है)। यह इस प्रकार से होता है:
यहाँ देख रहे हैं (http://www.docjar.com/html/api/org/apache/struts2/ServletActionContext.java.html) हम देखते हैं, जहां "pageContext" से आता है:।
93 public static PageContext getPageContext() {
94 return (PageContext) ActionContext.getContext().get(PAGE_CONTEXT);
95 }
getContext() (प्राप्त) एक वस्तु, जो हम जानते PageContext की तरह है रिटर्न । लेकिन कार्यान्वयन वर्ग क्या है? JSP में फिर
package com.quaternion.action.test;
import com.opensymphony.xwork2.ActionSupport;
public class RequestAccessTest extends ActionSupport{
public String getGreeting(){
return "Hello from Request AccessTest";
}
}
:
एक सरल गतिविधि बनाना
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<h1>Request Access Test</h1>
<%
HttpServletRequest r = (HttpServletRequest) pageContext.getRequest();
String aGreeting = (String) r.getAttribute("greeting");
System.out.println(aGreeting);
System.out.println("R's class is:" + r.getClass().getCanonicalName());
%>
</body>
</html>
मेरे कंसोल पर मैं मुद्रित देखें:
INFO: Hello from Request AccessTest
INFO: R's class is:org.apache.struts2.dispatcher.StrutsRequestWrapper
इसलिए हम वास्तव में एक साथ काम कर रहे StrutsRequestWrapper (अब हम जानते हैं कि हम वास्तव में इसके साथ क्या काम कर रहे हैं) ...
http://massapi.com/source/struts-2.2.1/src/core/src/main/java/org/apache/struts2/dispatcher/StrutsRequestWrapper.java.html
उपरोक्त लिंक को देखते हुए हम देखते हैं कि getAttribute वास्तव में ओवरराइड है।
लाइन 65 से शुरू होने पर, हम देखते हैं कि यह अनुरोध से मूल्य प्राप्त करने का प्रयास किया गया है, और फिर यदि यह विफल हो जाता है तो यह मूल्य स्टैक से बाहर निकलता है।
यह दस्तावेज कहां है? मुझे लगता है कि यह अभी तक दस्तावेज किया गया है;)
ओह फॉलो अप के रूप में, यह उपयोगी हो सकता है और कुछ struts2 जादू को हटा सकता है: http://struts.apache.org/2.0.14/docs/what-is- -actioncontext.html – Quaternion