Prepend the servlet path to /error and security paths

Cherry pick some changes manually from master