I have 2 types of text string that I need to escape:
1) name=ALICE " (double quote)
2) name=ALICE ' (single quote)
This is my codes:
if (name.indexOf('\'') >= 0){
name=StringEscapeUtils.escapeJavaScript(name);
System.out.println("escape by javascript " + name);
} else {
name=StringEscapeUtils.escapeHtml(name);
System.out.println("escape by html" + name);
}
The solution works correctly for both ( able to save both name texts in database)
However, the display is a bit off. How can I hide the backslash character from showing when escaping the single quote? I want the jsp to display ALICE' instead if ALICE\' & ensure able to save the result in db