I have to concur, this is one of the more annoying things about building
dynamic pages with current Java solutions.  There seems to be no intrinsic
support for html, such as a construction set of some kind (see
java.apache.org for a beginning attempt at such a beast), and most
importantly, an HTMLEncode function.

SUN:  ARE YOU LISTENING??!?  THIS MUST BE A PART OF THE API.  IT IS NOT
OPTIONAL.

FYI, Myriam, for better efficiency (for the time being) you should use the
toCharArray() function of a String (indexing into an array repeatedly is far
faster than calling an API to do it for you) and also change res to be a
StringBuffer and use res.append("&lt"); etc.

-taylor

----- Original Message -----
From: Myriam Pinon <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 25, 1999 2:01 AM
Subject: HTMLEncode


> Hi,
> I am new to JSP, migrating from ASP, and I am looking for equivalent Java
> functions for common ASP ones. I have found equivalents (and more!) for
most
> of them, but I miss an equivalent for Server.HTMLEncode, an ASP function
> that encodes a Unicode text into HTML. So far, I use the following code :
>
> String HTMLEncode( String str ) {
>  String res = "";
>
>  if( str == null ) return res;
>
>  for( int i = 0; i < str.length(); i++ ) {
>   char c = str.charAt( i );
>   switch( c ) {
>    case '<' : res += "&lt;"; break;
>    case '>' : res += "&gt;"; break;
>    case '&' : res += "&amp;"; break;
>    default : res += c;
>   }
>  }
>
>  return res;
> }
>
> this works fine, but I feel like rewriting the wheel. Is there such a
> function in the Java API ?
> Regards,
> MP
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff JSP-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to