• Post Reply Bookmark Topic Watch Topic
  • New Topic

Odd behaviour using <c:out> tag and EL in a JSP

 
aity myles
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my simple JSP code

when the code above was executed,i got this as the output

<b> is called a bold tag
<b> is called a bold tag
is called a bold tag
<b> is called a bold tag
<b> is called a bold tag


instead of

<b> is called a bold tag
<b> is called a bold tag
is called a bold tag
<b> is called a bold tag
<b> is called a bold tag

could someone please explain to me why the unexpected output. Thanks in anticipation of the assistance.



 
Varun Surpurkar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
From your code
${name}


<c:out value="<b> is called a bold tag "/>


<c:out value="${name}"/>
</body>
it is quite evident that ,you dont have a closing while constructing the request attribute.
The remaining tags


<c:out value="<b> is called a bold tag "/>


<c:out value="${name}"/>

from the html perspecitve are within the bold tag which is not closed when evaluated.
so the actual conversion occurs as attached.
You can notice that the third output $name is evaluated as is under a bold tag and remaining statements are within the tag which is not closed.
Hence all the statements after will be in bold.

For getting the desired output you shoud have set the requestAttribute as
<% request.setAttribute("name"," <b> is called a bold tag</b>");%>

Hope this helps.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Invalid HTML will usually result in unwanted results.

And, of course, this has nothing to do with any "odd behavior" of a tag; it's completely due to sloppy HTML.
 
aity myles
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!