public static String encodeForURL(String str){
  StringBuffer result=new StringBuffer();
  for (int i=0; i < str.length(); i++) {
    char ch=str.charAt(i);
    if (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9')     result.append(ch);
 else {
switch (ch) {
case '-':
case '_':
case '.':
case '!':
case '~':
case '*':
case '\'':
case '(':
case ')':
        result.append(ch);
      break;
default :
    result.append('%');
  result.append(hexchars[(ch & 0xf0) >> 4]);
result.append(hexchars[ch & 0x0f]);
break;
}
}
}
return result.toString();
}

public static String encodeForURL ( String str ) { StringBuffer result = new StringBuffer ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9' ) result . append ( ch ) ; else { switch ( ch ) { case '-' : case '_' : case '.' : case '!' : case '~' : case '*' : case '\'' : case '(' : case ')' : result . append ( ch ) ; break ; default : result . append ( '%' ) ; result . append ( hexchars [ ( ch & 0xf0 ) > > 4 ] ) ; result . append ( hexchars [ ch & 0x0f ] ) ; break ; } } } return result . toString ( ) ; }
escapes special characters not suitable for urls with " % xx "
