java Struts2 中的变量声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5323340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 10:39:10  来源:igfitidea点击:

Variable declaration in Struts2

javastruts2

提问by Lohit

How to declare a variable and assign value to that variable in Struts2?

如何在Struts2中声明一个变量并为该变量赋值?

回答by robsf

Use the set tag:

使用 set 标签:

<s:set var="myVar">hello</s:set>

read the var with:

使用以下命令读取 var:

<s:property value="#myVar"/>


Another example:

另一个例子:

<s:set name="personName" value="person.name"/>
Hello, <s:property value="#personName"/>. How are you?

where person is a bean in your value stack

在你的价值栈中,person 是一个 bean

回答by ThiefMaster

You shouldn't have to declare variables in JSPs. Do it in your Action and create a getter so you can access it from the JSP showing the action's output.

您不应该在 JSP 中声明变量。在您的 Action 中执行此操作并创建一个 getter,以便您可以从显示操作输出的 JSP 访问它。

回答by Umesh Awasthi

Well in struts2 we have concept of value stack and during request processing Struts2 framework will push the action on the top of value stack and its properties (Variable) will work as they are on the top of it.

在 struts2 中,我们有值堆栈的概念,在请求处理期间,Struts2 框架会将操作推送到值堆栈的顶部,其属性(变量)将在其顶部工作。

all you need to have getter and setter for your variable and you can than access values both (in/out) in struts2 with OGNL.OGNL is an expression language integrated with Struts2 which is capable of refereeing values from the value stack and also will do the data conversion (except custom type) for you

所有你需要为你的变量设置 getter 和 setter,你可以使用 OGNL.OGNL 访问 struts2 中的(输入/输出)值。OGNL 是一种与 Struts2 集成的表达式语言,它能够从值堆栈中引用值,也可以为您进行数据转换(自定义类型除外)