[英]HttpServletResponse.sendError() does not redirect to error page
I have the following code in doFilter() method, where I get application scoped bean. 我在doFilter()方法中有以下代码,在这里我获得了应用程序作用域bean。
if (request.getServletContext().getAttribute("resource")==null) {
response.sendError(503);
return;
}
I mapped 503 code to specific error page in web.xml. 我将503代码映射到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.
但地址栏中的地址不会因错误页面地址而改变:请求的servlet的地址离开那里。 Is it right behaviour?
这是正确的行为吗? I'd like to inform explicitly about redirection to error page.
我想明确告知重定向到错误页面。 Is it only possible with sendRedirect()?
是否只能使用sendRedirect()?
This is the correct behavior. 这是正确的行为。 When you use sendError() it will respond to the current request with an error page.
当您使用sendError()时,它将使用错误页面响应当前请求。 If you instead want the URL to change to the error page URL, you will need to use sendRedirect() to respond with a redirect.
如果您希望将URL更改为错误页面URL,则需要使用sendRedirect()来响应重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.