Example: Extending PageListServlet

See the Code example disclaimer for legal information about this code example.

This example shows how a servlet extends the PageListServlet class and determines the markup-language type required by the client. The servlet then uses the callPage() method to call an appropriate JavaServer Pages (JSP) file. In this example, the JSP file that provides the correct markup language for the response is Hello.page.

public class HelloPervasiveServlet extends PageListServlet implements Serializable {

  // doGet -- Process incoming HTTP GET requests
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

    // This is the name of the page to be called:
    String pageName = "Hello.page";
 
    // First check if the servlet was invoked with a queryString that contains a
    // markup-language value. For example, if the servlet is invoked with the URL
    // http://localhost/servlets/HelloPervasive?mlname=VXML, use this method:
    String mlname= getMLNameFromRequest(request);

    // If no markup language type is provided in the queryString, then try to
    // determine the client type from the request, and use the markup-language name
    // configured in the client_types.xml file.   
    if (mlName == null) {
      mlName = getMLTypeFromRequest(request);
    }
    
    try {
      // Serve the request page.
      callPage(mlName, pageName, request, response);
    }
    catch (Exception e) { 
      handleError(mlName, request, response, e);
    }
  }
}