• Post Reply Bookmark Topic Watch Topic
  • New Topic

<c:out value="${param}"/> vs ${param}  RSS feed

 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

What't the difference between this two statements <c:out value="${param}"/> and ${param}? Is not exactly the same if you don't use the scapeXml attribute? Is there any special reason to use the c tag?

Thanks in advance for your answers.
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c: out> tag has one attribute i.e. default that is get printed to output if value spacified is null.
e.g.
suppose we are printing userName in to first page of appliation.
if user come from login then we put his/her name in session as "userName"
else we want to print guest.


then simply put,
<c: out value='${sessionScope. userName}' default='guest' />

if userName in session it will prints name of user else guest.

to do this by EL we need to if else condition for checking userName.
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot completly about the default attribute. Thanks.
I asked this because in the application I am working I have seen several times things like <c:out value="${param}"/> that makes not to much sense for me if they are alone.

Thanks for your reply ;)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The primary purpose of using <c:out> is to take advantage of the automatic HTML-encoding. It should be used for all non-trusted data.
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The primary purpose of using <c:out> is to take advantage of the automatic HTML-encoding. It should be used for all non-trusted data.


Ok, thanks for your answer ;)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!