Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Easy way to convert text characters to html?

 
Peter Bergoff
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing servlets with text in them. Every time I have a comma, apostrophe, ampersand or similar characters I have to use the html special characters. Is there some easier way to do this other than me manually searching for the character and replacing with the html code equivalent? If I don't convert the characters an ampersand becomes a question mark ect . ..

Thanks!
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Bergoff wrote:Hi,

I am writing servlets with text in them. Every time I have a comma, apostrophe, ampersand or similar characters I have to use the html special characters. Is there some easier way to do this other than me manually searching for the character and replacing with the html code equivalent? If I don't convert the characters an ampersand becomes a question mark ect . ..

Thanks!


please see http://stackoverflow.com/questions/655746/is-there-a-jdk-class-to-do-html-encoding-but-not-url-encoding
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Bergoff wrote: I am writing servlets with text in them. Every time I have a comma, apostrophe, ampersand or similar characters I have to use the html special characters.

No, you don't. The ampersand, yes, you must use & because it is in the introducer for HTML entities, but commas and most other characters do not need to be HTML-encoded.

Obviously, the angle brackets need to be encoded into HTML entities.
 
Peter Bergoff
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear and Tim - You guys rock. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic