开发者

Variable declaration in Struts2

How to declare a variable and assign value to that variable in Str开发者_运维技巧uts2?


Use the set tag:

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

read the var with:

<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


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.


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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜