开发者

What's the equivalent of addslashes() in JSP / Servlets?

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜