Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpServletResponse.sendError() does not redirect to error page

Tags:

java

servlets

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()?

like image 308
Grade Avatar asked Mar 10 '13 03:03

Grade


1 Answers

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.

like image 98
worpet Avatar answered Oct 23 '22 07:10

worpet