How to add slashes to a particular string in JSP?
I want to convert this PHP code $subj 开发者_StackOverflow中文版= addslashes($_POST['txtsubjct']);
to JSP.
addslashes()
is not particularly needed:
If you want to protect from sql-injections, use PreparedStatement
public static String addSlashes(String s) {
s = s.replaceAll("\\\\", "\\\\\\\\");
s = s.replaceAll("\\n", "\\\\n");
s = s.replaceAll("\\r", "\\\\r");
s = s.replaceAll("\\00", "\\\\0");
s = s.replaceAll("'", "\\\\'");
return s;
}
精彩评论