File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Easy way to convert text characters to html? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Easy way to convert text characters to html?" Watch "Easy way to convert text characters to html?" New topic
Author

Easy way to convert text characters to html?

Peter Bergoff
Ranch Hand

Joined: Apr 07, 2004
Posts: 103
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

Joined: Apr 30, 2003
Posts: 820

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

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Bergoff
Ranch Hand

Joined: Apr 07, 2004
Posts: 103
Bear and Tim - You guys rock. Thanks.
 
Don't get me started about those stupid light bulbs.
 
subject: Easy way to convert text characters to html?
 
Similar Threads
textarea
html:text not supporting non engilsh characters
Breaking up text in lines
HTMLEncoding?
HTML Tag problem