Class PageServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
fc.web.servlet.FCBaseServlet
fc.web.page.PageServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class PageServlet extends FCBaseServlet
The page servlet. Handles web requests that are mapped to a molly server page (typically via a *.mp extension).

All uncaught exceptions in the rendered page are wrapped in a ServletException and thrown up to the servlet container. These are typically handled by the container by either showing the full stack trace to the user or using a error page configured in the containers web.xml file. This latter approach is recommended for production use. An example is shown below.

<!-- in web.xml --> <span class="invalid-tag">invalid input: '&lt;'</span>error-page&gt; <span class="invalid-tag">invalid input: '&lt;'</span>exception-type&gt;java.lang.Exception<span class="invalid-tag">invalid input: '&lt;'</span>/exception-type&gt; <location>/errors/error.mp</location> <span class="invalid-tag">invalid input: '&lt;'</span>/error-page&gt;

However, if some partial response has already been sent to the browser and an exception occurs (later in java code on that same page), then the error page (if configured in web.xml) cannot typically be displayed.

For that scenario, this servlet accepts an optional error_page initialization parameter. This parameter, if present, should contain a webapp-relative path to an error page that will be included in the rendered page if there is an exception after the response has been committed. This error page is then included in the response sent to the browser.

The following attributes are available in the error page

jakarta.servlet.error.status_code 
jakarta.servlet.error.exception
jakarta.servlet.error.request_uri
jakarta.servlet.error.servlet_name

This servlet also accepts an optional 404_page parameter. This parameter, if present, should contain a web document root-relative path to a 404 or not found page. This page is different than the error_page because it signifies a badly typed URL request for a page that does not exist. (for example, http://somehost/badpage.mp). This parameter should be the same as the 404 error code parameter in web.xml. For example:

<!-- in web.xml --> <span class="invalid-tag">invalid input: '&lt;'</span>error-page&gt; <span class="invalid-tag">invalid input: '&lt;'</span>error-code&gt;404<span class="invalid-tag">invalid input: '&lt;'</span>/error-code&gt; <location>/errors/not_found.html</location> <span class="invalid-tag">invalid input: '&lt;'</span>/error-page&gt;

See Also:
  • Field Summary

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    init(jakarta.servlet.ServletConfig conf)
     
     

    Methods inherited from class FCBaseServlet

    getLog, stats

    Methods inherited from class jakarta.servlet.http.HttpServlet

    service

    Methods inherited from class jakarta.servlet.GenericServlet

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

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • init

      public void init(jakarta.servlet.ServletConfig conf) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Servlet
      Overrides:
      init in class FCBaseServlet
      Throws:
      jakarta.servlet.ServletException
    • toString

      public String toString()
      Overrides:
      toString in class FCBaseServlet
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Servlet
      Overrides:
      destroy in class FCBaseServlet