开发者

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

开发者 https://www.devze.com 2023-02-12 03:01 出处:网络
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:

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

精彩评论

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