This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Escape all special characters in HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Escape all special characters in HTML" Watch "Escape all special characters in HTML" New topic
Author

Escape all special characters in HTML

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

Hi All,

Is there a simple (built-in) method in java for escaping a string containing special characters to HTML? I came across this page which is useful but not complete. There's a couple hundred in this table that I would like to add. Right now, my only solution is to manually edit the text of the first page to include more of the codes of the second, but I feel like I'm re-inventing the wheel.

Is there a better way to do this?

-Scott


My Blog: Down Home Country Coding with Scott Selikoff
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Scott,
Have you looked at Apache Commons. Not built in, but reusable. It sounds like StringEscapeUtils has what you want.

[edited to fix typo]


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

Thanks! I'll give it a shot and see.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Escape all special characters in HTML
 
Similar Threads
backslash is removed from the parameter when javascript function get the parameter from java call
Escaping HTML Text
cancel button problem
Problem with escape chars...
"Could not create task of type: echo"