We are trying to use ESAPI in our web app. We have following function in servlet.
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
response.setHeader(SearchConstants.CACHE_CONTROL_HEADER,
SearchConstants.MAX_AGE_ZERO);
response.setHeader(SearchConstants.CACHE_CONTROL_HEADER,
SearchConstants.NO_CACHE);
response.setDateHeader(SearchConstants.EXPIRES_HEADER, 0);
response.setHeader(SearchConstants.PRAGMA_HEADER, "no cache");
result = processRequest(request, response);
if (SearchConstants.XSLT_ERROR_MSG.equals(result)) {
LOGGER.error("XSLT ERROR FOR QUERY STRING: "
+ request.getQueryString());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} else if (SearchConstants.SEARCH_PAGE_MISSING_MSG.equals(result)) {
LOGGER.error("NOT FOUND ERROR FOR QUERY STRING: "
+ request.getQueryString());
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
final PrintWriter out = response.getWriter();
out.println(result); // this works
// out.println(ESAPI.encoder().encodeForHTML(result));
}
}
In above code if I use out.println(ESAPI.encoder().encodeForHTML(result));
, this actually prints html as text on browser. i.e. it's showing like simple text <html>
other contents.. </html>
, instead of rendering html page. result
is nothing but html contents which needs to get rendred on client.
We are doing something wrong over here. Please provide some pointers. How we can achieve encoding over here?