JAVA/공부

web-xml을 이용한 커스텀 에러 페이지

GaeGim 2022. 9. 18. 16:33
반응형
  • web.xml 파일을 통해서 오류 코드나 오류 location 그리고 오류 페이지를 호출하는 방식

 

 

 

 

  • 에러 페이지 만들기

 

 

 

 

  • web.xml 파일에 코드 추가
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">
  
  
  
  //에러 페이지 추가할 내용
<error-page>
      <error-code>404</error-code>
      <location>/error/404error.jsp</location>
  </error-page>
  //여기까지 써주기
  
  
  
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
  
  <servlet>
      <servlet-name>ServletTest</servlet-name>
      <servlet-class>ServletTest</servlet-class>
  </servlet>

  <servlet-mapping>
      <servlet-name>ServletTest</servlet-name>
      <url-pattern>/test</url-pattern>
      
  </servlet-mapping>
</web-app>

 

 

 

 

  • 실행 결과

 

 

 

반응형

'JAVA > 공부' 카테고리의 다른 글

JSP 스코프  (0) 2022.09.18
HTTP와 HTTPS의 차이점  (0) 2022.09.16
인코딩 해결법  (0) 2022.09.15
서블릿 매핑  (0) 2022.09.15
HttpServlet 클래스  (0) 2022.09.15