Grade
Grade

Reputation: 574

HttpServletResponse.sendError() does not redirect to error page

I have the following code in doFilter() method, where I get application scoped bean.

    if (request.getServletContext().getAttribute("resource")==null) {
        response.sendError(503);
        return;
    }

I mapped 503 code to specific error page in web.xml. And I really get content of error page in browser, if error occurs. But the address in address bar doesn't change for error page address: an address of requested servlet leaves there. Is it right behaviour? I'd like to inform explicitly about redirection to error page. Is it only possible with sendRedirect()?

Upvotes: 6

Views: 4408

Answers (1)

worpet
worpet

Reputation: 3893

This is the correct behavior. When you use sendError() it will respond to the current request with an error page. If you instead want the URL to change to the error page URL, you will need to use sendRedirect() to respond with a redirect.

Upvotes: 4

Related Questions