Struts 中静态包含页面的参数传递 2

Parameter Passing for statically included page in Struts 2

我有一个父文件,其中静态包含了我的 JSP。

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

在包含的文件中,我想使用 Struts2 标签访问父 JSP 的变量。

请告诉我是否可以,或者我是否应该使用 动态 包含。

您无法访问变量,但可以使用 OGNL 从值堆栈访问变量。请参阅 OGNL Basics 以了解有关 Struts 中变量的更多信息以及如何使用它们。

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.

要动态包含 JSP 内容,请使用 s:include 标签

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"/>