0

I have a java bean which get populated from DB. The fields of bean may contain characters like < or . Right now when i am trying to display them, the string get truncated from the point where any of these character appear.

So if i have this is a </ test message and i want to see if it displays. HTML will display only this is a string only. How can i display full string.

P.S: For some reasons, I can't change string in the database. I have to rely whatever i have in db.

Em Ae
  • 7,519
  • 22
  • 73
  • 143

2 Answers2

0

One option is to surround the text with the HTML tag "pre"

The other option is to escape the text to make it XML friendly. Commons-lang has a utility for this. http://commons.apache.org/lang/api-release/org/apache/commons/lang3/StringEscapeUtils.html

JustinKSU
  • 4,696
  • 2
  • 26
  • 49
0

For a simple solution, see methods of the String class:

  • String.replace()
  • String.replaceAll()
  • String.replaceFirst()

Note: replaceAll and replaceFirst require a regex pattern to match, not a plain match string. Check Pattern class on how to build a suitable regex.

Remember that in HTML, the symbols < and > can be displayed using &lt; and &gt;. If you don't understand what I'm talking about, just View Source on this page and find my last sentence in the source.

ADTC
  • 8,174
  • 5
  • 63
  • 86