< s:property ..>和有什么区别?和$ {param}

< s:property ..>和有什么区别?和$ {param}

问题描述:

在struts中,我注意到有两种访问变量的不同方法.我很好奇这是什么区别,以及何时正确使用它们之间的区别.例如,假设我们像这样设置变量高度:

In struts I notice there are two different ways to access variables. I am curious what the difference is and when to properly use each one. For example, suppose we set the variable height like so:

<s:set var="height">300px</s:set>

现在我可以用两种方式使用它:

Now I can use it two ways:

<div style="height: ${height}">&nbsp;</div>

.. or ..

<div style="height: <s:property value='#height' />">&nbsp;</div>

有什么区别,哪个更好用?

What is the difference, and which is better to use?

struts2 <property>提供了除${}提供的功能之外的其他功能,例如,如果变量为null,则提供默认值,并控制HTML转义

The struts2 <property> provides additional functionality beyond what ${} offers, such as providing a default value if the variable is null, and control over HTML-escaping.