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

Parameter Passing for statically included page in Struts 2(Struts 2中静态包含页面的参数传递)

本文介绍了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.

请让我知道是否有可能或者我应该去 dynamic 包含.

Please let me know if it is possible or should I go for dynamic include.

推荐答案

您不能访问变量,但可以使用 OGNL 从值堆栈中访问变量.请参阅 OGNL 基础知识 了解更多关于 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 访问特殊的命名对象(确切地说是请求范围属性),但现在使用 #foo 访问特殊变量.但是,需要注意的是,#foo 确实 访问请求属性.因为 XWork 不是只为 web 构建的,所以没有请求属性"的概念,因此 #foo 只是对 OgnlContext other 中另一个对象的请求比根.

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 标签

To include JSP content dynamically use s:include tag

包括 servlet 的输出(servlet 或 JSP 页面的结果).

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

注意:提供给包含页面的任何附加 params 都无法通过 <s:property...> 标签在呈现的页面中访问,因为没有 valuestack将被创建.但是,您可以通过 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中静态包含页面的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Struts 2中静态包含页面的参数传递

基础教程推荐