2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

springで共通エラーページへ飛ばす

Last updated at Posted at 2019-06-25

プログラム

このように、400エラーのときも403エラーのときも、全て同じように
「common_error.jsp」を指定することで、下記のエラーが出ても、tomcatのエラー表示はされなくなり、自分で作ったページが表示されます。
今回はどのエラーでも同じページを表示するようにしていますが、
よくある404のときは404の可愛い画像を表示したかったら、そのページを指定すればよいということになります。

web.xml
 <error-page>
    <error-code>400</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
    <error-page>
    <error-code>403</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
  <error-page>
    <error-code>405</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
  <error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
    <error-page>
    <error-code>501</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
    <error-page>
    <error-code>502</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
  
    <error-page>
    <error-code>503</error-code>
    <location>/WEB-INF/jsp/common_error.jsp</location>
  </error-page>
2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?