/**
* è·å表ååæ°çæ°å¼ã
*
* param escapeHTMLTags escapeHTMLTags=trueä¸å
许使ç¨htmltagã
*/
public static String getEscapeHTMLParameter(HttpServletRequest request
, String paramName
, String defaultValue) {
String temp = StringUtils.escapeHTMLTags(RequestUtils.getParameter(request
, paramName, true));
if ( (temp == null) || (temp.equals(""))) {
temp = defaultValue;
}
return StringUtils.nullToString(temp);
}
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<') {
buf.append("<");
}
else if (ch == '>') {
buf.append(">");
}
else {
buf.append(ch);
}
}
return buf.toString();
}
温馨提示:答案为网友推荐,仅供参考