• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<c:out> and "<, >, &"

 
Tyler Wright
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

For question 1 on page 378 of Charles Lyon's "SCWCD Study Companion":

The answer is given as C...

Note: I had to put the entityReferences as &_amp; and &_lt; inorder not to have them translated into '&' and '<'
*************************************************
When I ran this in tomcat 5.5.x.x I got:
'Facts & Figures: 5 < 6'

If you try this at home remember to include the taglib directive:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


Am I missing something?

Tyler...
 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of escapeXml attribute in <cut> tag defaults to 'true'. So you'll get display any XML entities, which is not rendered.
 
Chinmaya Chowdary
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tyler. The container sends the response in the form of "Facts &_amp; Figures: 5 &_lt; 6". The browser sees the character entity codes & < and it places the equivalent characters like & <. If you see the page source it will be clear.
 
Chinmaya Chowdary
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, Javaranch is not using cut , thats why i used &_amp and &_lt, actually there is no _. Sorry for duplicate message. Thankyou.
 
Tyler Wright
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Thanks for the quick response...I coded this up based upon your responses:


Which produced this in the browser:
In the browser:
**********************
this is cut escapeXml="false" :
& %amp;

this is a test

this is cut escapeXml="true" :
& %amp; <p> <html><table><th>this is a test</th></table></html>

***************************

But, the view source produced:
<p>
this is cut escapeXml="false" :<br>
& %amp; <p> <html><table><th>this is a test</th></table></html>
</p>

<p>
this is cut escapeXml="true" :<br>
& %amp; <p> <html><table><th>this is a test</th></table></html>
</p>
*****************************************************
My confusion with this came from the browser's presentation; I forgot about the source....

Thanks for clarifying this...it was really bugging me.

PS: To see what is really going on here, the jsp code should be executed and the results viewed your browser and the source viewed with your view source...in this post the entityReferences are automatically translated to their HTML presentations so the effect is lost.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic