Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Escaping HTML Text

 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there something in the Java API that will take a String of HTML and escape all the special characters for you?

For example, if I have a String that looks like this:

<html>

Can I pass that String to some method and get this back?

& lt;html& gt;

Thanks.

Edit: I put spaces in the tags just so that they'd show properly instead of being converted to < and >, respectively. Hopefully, you get the idea.
[ May 09, 2005: Message edited by: Corey McGlone ]
 
Darryl Pierce
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Corey McGlone:
Is there something in the Java API that will take a String of HTML and escape all the special characters for you?

For example, if I have a String that looks like this:

<html>

Can I pass that String to some method and get this back?

& lt;html& gt;


See String.replace()
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you might want to take a look at

org.apache.commons.lang.StringEscapeUtils

Its in

Core Language Utilities
The Apache Jakarta Commons Lang Library, version 2.0

Downloadable from

http://jakarta.apache.org/commons/lang/

Enjoy,

J.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic