Here you can find the source of HTMLFilter(String the_txt)
Parameter | Description |
---|---|
the_txt | The raw text as entered into a GET or POST command. |
public static String HTMLFilter(String the_txt)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w . ja v a2 s . c o m*/ * Cleans up entered text to make it XML compatible and to prevent SQL injection tricks. * @param the_txt The raw text as entered into a GET or POST command. * @return The cleaned text. */ public static String HTMLFilter(String the_txt) { if (the_txt == null) { return null; } char content[] = new char[the_txt.length()]; the_txt.getChars(0, the_txt.length(), content, 0); StringBuffer result = new StringBuffer(content.length + 50); for (int i = 0; i < content.length; i++) { switch (content[i]) { case '<': result.append("<"); break; case '>': result.append(">"); break; case '&': result.append("&"); break; case '"': result.append("""); break; case '\'': result.append("'"); break; default: result.append(content[i]); } } return result.toString(); } }