参数传递为Struts 2中静态包含的页面 [英] Parameter Passing for statically included page in Struts 2

查看:226
本文介绍了参数传递为Struts 2中静态包含的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父文件,我的JSP是静态包含的。

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

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

在包含的文件中,我想使用Struts2标签访问父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.

推荐答案

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

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.


除了上面给出的示例和描述,自从WebWork 1.x起,EL中有一些重大变化。最大的一个是不再使用正斜杠 / 访问属性,但使用点。另外,我们现在使用 [n] ,而不是使用 .. 遍历堆栈,其中n是一些正数数。最后,在WebWork 1.x中,可以使用 @foo 访问特殊命名对象(请求范围属性准确),但现在使用<$ c访问特殊变量$ C> #foo 。但是,重要的是要注意 #foo 访问请求属性。因为XWork不是仅为Web构建的,所以没有请求属性的概念,因此 #foo 仅仅是对<$ c $中另一个对象的请求c> OgnlContext 除根之外。

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 tag

To include JSP content dynamically use s:include tag


包含servlet的输出(servlet或JSP页面的结果)。

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

注意:任何额外的<$ c提供给包含页面的$ c> params 无法通过< s:property ...> 标记在呈现的页面中访问不会创建任何价值堆叠。但是,您可以通过 HttpServletRequest 对象在servlet中访问它们,或者通过scriptlet从JSP页面访问它们。

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.

如何访问参数

参数作为请求参数传递,因此请使用 $ {param.ParamName} 表示访问它们。不要使用属性标记来访问包含文件中的参数。

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

这篇关于参数传递为Struts 2中静态包含的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆