Servlet中处理404错误

问题描述 投票:0回答:1

我正在尝试根据状态代码重定向到其他错误jsp

statusCode = (Integer) req.getAttribute("javax.servlet.error.status_code") 但它抛出一个空指针错误。我的web.xml看起来像

<exception-type>404</exception-type><location>/AppExceptionHandler</location>
servlets http-status-code-404
1个回答
0
投票

我认为web.xml中的条目不正确。它应该像下面这样。异常类型不应该是代码,而应该是下面的类。

异常类型包含完全限定的类Java异常类型的名称。

  <error-page>
    <exception-type>javax.servlet.ServletException</exception-type>
    <location>/AppExceptionHandler</location>
  </error-page>

如果您想处理404,请执行以下操作。

<error-page>
  <error-code>404</error-code>
  <location>/AppExceptionHandler</location>
</error-page>

0
投票

sdvfvth rthgtr汞柱rtgwfrgbvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvcsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzzzertttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttgvsazdfv DFV

© www.soinside.com 2019 - 2024. All rights reserved.