The 1.java code sometimes encounters security problems with code injection, and in order to prevent this, a filtering function is added. The main is to filter the full-width characters, the URL can not recognize the full-width characters converted to half-width characters
1 Public classTest {2 Public Static voidMain (string[] args) {3String t= "Ffac ※00☆№CCC";4 System.out.println (t);5 System.out.println (Tosemiangle (t));6 }7 8 /**9 * Full-width space is 12288, half-width space isTen * Other character half-width (33-126) and full-width (65281-65374) correspondence is: The difference between the 65248 One * A * Convert full-width characters in a string to half-width - * @paramsrc Any string containing full-width to convert - * @returnstring after conversion the */ - Public Staticstring Tosemiangle (string src) { - Char[] C =Src.tochararray (); - for(intindex = 0; Index < c.length; index++) { + if(C[index] = = 12288) {//Full-width spaces -C[index] = (Char) 32; +}Else if(C[index] > 65280 && c[index] < 65375) {//other full-width characters AC[index] = (Char) (C[index]-65248); at } - } - returnstring.valueof (c); - } -}
Output Result:
FFAC ※00☆№CCC
FFAC ※00☆№CCC
Java Full-width character turn half-width character