The javadoc for javax.servlet.http.HttpServletResponse is a little vague on the difference between what rules encodeURL and encodeRedirectURL
javax.servlet.http.HttpServletResponse
encodeURL
encodeRedirectURL
encodeURL() is used for all URLs in a servlet's output. It helps session ids to be encoded with the URL.
encodeURL()
encodeRedirectURL() is used with res.sendRedirect only. It is also used for encoding session ids with URL but only while redirecting.
encodeRedirectURL()