Class ErrorPageFilter

java.lang.Object
org.springframework.boot.web.servlet.support.ErrorPageFilter
All Implemented Interfaces:
jakarta.servlet.Filter, ErrorPageRegistry, org.springframework.core.Ordered

public class ErrorPageFilter extends Object implements jakarta.servlet.Filter, ErrorPageRegistry, org.springframework.core.Ordered
A Servlet Filter that provides an ErrorPageRegistry for non-embedded applications (i.e. deployed WAR files). It registers error pages and handles application errors by filtering requests and forwarding to the error pages instead of letting the server handle them. Error pages are a feature of the servlet spec but there is no Java API for registering them in the spec. This filter works around that by accepting error page registrations from Spring Boot's ErrorPageRegistrar (any beans of that type in the context will be applied to this server).
Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the servlet attribute containing request URI.

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addErrorPages(ErrorPage... errorPages)
    Adds error pages that will be used when handling exceptions.
    void
     
    void
    doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain)
     
    protected String
    getDescription(jakarta.servlet.http.HttpServletRequest request)
    Return the description for the given request.
    int
     
    void
    init(jakarta.servlet.FilterConfig filterConfig)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ERROR_REQUEST_URI

      public static final String ERROR_REQUEST_URI
      The name of the servlet attribute containing request URI.
      See Also:
  • Constructor Details

    • ErrorPageFilter

      public ErrorPageFilter()
  • Method Details

    • init

      public void init(jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Filter
      Throws:
      jakarta.servlet.ServletException
    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Specified by:
      doFilter in interface jakarta.servlet.Filter
      Throws:
      IOException
      jakarta.servlet.ServletException
    • getDescription

      protected String getDescription(jakarta.servlet.http.HttpServletRequest request)
      Return the description for the given request. By default this method will return a description based on the request servletPath and pathInfo.
      Parameters:
      request - the source request
      Returns:
      the description
      Since:
      1.5.0
    • addErrorPages

      public void addErrorPages(ErrorPage... errorPages)
      Description copied from interface: ErrorPageRegistry
      Adds error pages that will be used when handling exceptions.
      Specified by:
      addErrorPages in interface ErrorPageRegistry
      Parameters:
      errorPages - the error pages
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Filter
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered