For example, in my Java servlet project I return the text that user entered on the site to the same site (and on multiple places inside HTML and JavaScript, potential XSS attack).
Is it correct to use Apache StringEscapeUtils class to escape both HTML and JavaScript at the same time like this:
String sample_string=escapeEcmaScript(escapeHtml4(request.getParameter("sample_string")));