Parameter Passing for statically included page in

2019-02-20 06:01发布

I have a parent file where my JSP is statically included.

<%@include file="test.jsp" %>

In the included file I want to access the variable of parent JSP using Struts2 tag. Please let me know if it is possible or should I go for dynamic include.

1条回答
劳资没心,怎么记你
2楼-- · 2019-02-20 06:25

You can't access the variable but you can access the variable from the the value stack using OGNL. See OGNL Basics to learn more about variables in Struts and how to use them.

Besides the examples and descriptions given above, there are a few major changes in the EL since WebWork 1.x. The biggest one is that properties are no longer accessed with a forward slash / but with a dot .. Also, rather than using .. to traverse down the stack, we now use [n] where n is some positive number. Lastly, in WebWork 1.x one could access special named objects (the request scope attributes to be exact) by using @foo, but now special variables are accessed using #foo. However, it is important to note that #foo does not access the request attributes. Because XWork is not built only for the web, there is no concept of "request attributes", and thus #foo is merely a request to another object in the OgnlContext other than the root.

To include JSP content dynamically use s:include tag

Include a servlet's output (result of servlet or a JSP page).

Note: Any additional params supplied to the included page are not accessible within the rendered page through the <s:property...> tag since no valuestack will be created. You can, however, access them in a servlet via the HttpServletRequest object or from a JSP page via a scriptlet.

How To access parameters

Parameters are passed as request parameters, so use the ${param.ParamName} notation to access them. Do not use the property tag to access parameters in included files.

<s:include value="test.jsp"/>
查看更多
登录 后发表回答