How to access the Struts value stack from an HttpServletRequest object?

I came across some code that accesses a value that is stored in the struts value stack by simply calling getAttribute () on the HttpServletRequest object. I did not think it was possible, and where is this documented?

Code from the action class (it does not add it to the class only on the value stack):

private PaginatedChunk searchResults;   


public PaginatedChunk getSearchResults() {
    return searchResults;
}

public void setSearchResults(PaginatedChunk searchResults) {
    this.searchResults = searchResults;
}

This is the code in the user tag that pulls the value from the request (and it works !?):

HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
PaginatedChunk searchResults = (PaginatedChunk)  request.getAttribute("searchResults");

Can someone explain to me how this works? I thought the Stack value was not directly accessible through the request.

We run struts2 v2.1.8.1

+5
source share
1 answer

. , , . , , - , . pageContext , - , ( ). :

(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(). get() , , , PageContext. ?

:

package com.quaternion.action.test;

import com.opensymphony.xwork2.ActionSupport;

public class RequestAccessTest extends ActionSupport{
    public String getGreeting(){
        return "Hello from Request AccessTest";
    }
}

JSP:

<%@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 class is:" + r.getClass().getCanonicalName());
        %>
    </body>
</html>

:

INFO: Hello from Request AccessTest
INFO: R 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, , , , , .

? , , ;)

+5