• Post Reply Bookmark Topic Watch Topic
  • New Topic

html encode

 
Steven Bergsten
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an easy way to map all characters, such as < to < within a String? I need to be able to show an html code sample in a servlet generated html page.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do a google search on 'escape HTML in java string' you'll find a few different places where people have implemented just the behaviour you're looking for.

Or, if you're using JDK1.4, you might attempt a regular expression to replace all occurences of < with &lt; and > with &gt;
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!