• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

character translation

 
Gregg Kelly
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string being returned from a bean that contains a HTML formatted message. something like:

"<font color=#00FF00>This is a message"

It appears during processing that the angle brackets are being translated into < and > codes. How do I disable this translation??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you emitting the string on the page?
 
Gregg Kelly
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have provided some env specs. I'm using:
tomcat 5.5.12
struts 1.2.8
os - solaris 10

I'm using the struts framework to populate a request bean for a jsp page to retrieve the value. I have verified that the form bean propertyt is correctly assigned. In the cited example the property is:
"<font color=#00FF00>This is a message"

I use a jsp page for presentation -- the snippet from the jsp:
<h1>
<bean:write name="xxxForm" property="mystr"/>
</h1>

The code you see on the browser is:
<h1>
*lt;font color=#00FF00*gt; This is a message
</h1>

replace * with &. So it appears the data transfer from the form bean to the JSP page goes through a translator. Is this correct??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default the <bean:write> tag will html-encode the output. I think you can use the filter attribute to turn it off.

It's very uncommon -- and not a good separation of concerns -- to emit HTML from the back end in this way. That's why tags like <bean:write> and the JSTL <cut> tag encode the output by default.

I'd also suggest that you look into using CSS for stlying rather than deprecated tags like <font>.
[ February 11, 2006: Message edited by: Bear Bibeault ]
 
Gregg Kelly
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear!! Setting filter="false" did the trick.

I agree with your design observations and recommendations. This data field happens to be a one-off case where it is much more efficient to construct it at the back-end.

Thanks again for your help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Gregg, and welcome to the Ranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic