net.i2p.servlet

## Class ErrorServlet

- java.lang.Object
- - javax.servlet.GenericServlet
  - - javax.servlet.http.HttpServlet
    - - net.i2p.servlet.ErrorServlet

- All Implemented Interfaces:
    Serializable, Servlet, ServletConfig

      public class ErrorServlet
      extends HttpServlet

  Common servlet for errors This is intended for webapps and local plugins. It is not appropriate for eepsites or remotely-accessible plugins, as it uses local console resources. See http://www.eclipse.org/jetty/documentation/current/custom-error-pages.html for how to add to web.xml or see examples in bundled webapps. Init parameters:
  - CSSPath - absolue URL of CSS to reference, starting with /, defaults to console theme
  - name - webapp or plugin name, will be translated with bundle, e.g. SusiMail
  - bundle - package of translation bundle, e.g. net.i2p.susimail.web.messages
  Most strings are translated with the console bundle, as we're using the same strings as in error.jsp and error500.jsp. Supported error codes: 403, 404, and 500+. Others must be added here.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ErrorServlet()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `_t(String s)` translate a string, console bundle
    `protected String` | `_t(String s, Object o)` translate a string, console bundle
    `protected String` | `_t(String s, Object o, Object o2)` translate a string, console bundle
    `protected String` | `_w(String s)` translate a string, with webapp bundle
    `protected void` | `doGet(HttpServletRequest req, HttpServletResponse resp)`
    `protected void` | `doPost(HttpServletRequest req, HttpServletResponse resp)` Needed if the errored page was a POST
    `void` | `init()`
    `protected void` | `outputMessage(PrintWriter out, int errorCode, String errorMsg, String errorURI, Throwable errorCause)` Override for specific cases.

    - ### Methods inherited from class javax.servlet.http.HttpServlet

      `doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service`

    - ### Methods inherited from class javax.servlet.GenericServlet

      `destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ErrorServlet

          public ErrorServlet()

  - ### Method Detail

    - #### _t

          protected String _t(String s)

      translate a string, console bundle

    - #### _t

          protected String _t(String s,
                              Object o)

      translate a string, console bundle

    - #### _t

          protected String _t(String s,
                              Object o,
                              Object o2)

      translate a string, console bundle

    - #### _w

          protected String _w(String s)

      translate a string, with webapp bundle

    - #### doGet

          protected void doGet(HttpServletRequest req,
                               HttpServletResponse resp)
                        throws ServletException,
                               IOException

      Overrides:
        `doGet` in class `HttpServlet`
      Throws:
        `ServletException`
        `IOException`

    - #### doPost

          protected void doPost(HttpServletRequest req,
                                HttpServletResponse resp)
                         throws ServletException,
                                IOException

      Needed if the errored page was a POST
      Overrides:
        `doPost` in class `HttpServlet`
      Throws:
        `ServletException`
        `IOException`

    - #### init

          public void init()
                    throws ServletException

      Overrides:
        `init` in class `GenericServlet`
      Throws:
        `ServletException`

    - #### outputMessage

          protected void outputMessage(PrintWriter out,
                                       int errorCode,
                                       String errorMsg,
                                       String errorURI,
                                       Throwable errorCause)

      Override for specific cases. This supports 403, 404, and 500+. Output HTML that goes inside the div.
      Parameters:
        `errorCode` - e.g. 404
        `errorMsg` - non-null, may be empty, already HTML-escaped
        `errorURI` - non-null, may be empty, already HTML-escaped
        `errorCause` - may be null