Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the Difference Between <s:property ..> and ${param}

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?

like image 833
PKKid Avatar asked Jan 24 '23 10:01

PKKid


2 Answers

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.

like image 91
skaffman Avatar answered Jan 26 '23 01:01

skaffman


Also you can use ${} inside another struts 2 tag. You can not nestle struts tags inside each other.

like image 32
froderik Avatar answered Jan 25 '23 23:01

froderik