HttpController

HttpController is the servlet-side entry point for ordinary HTTP requests. It resolves the requested HttpAction, calls perform(), and renders the returned Component.

Overview

A concrete controller generally extends HttpController, declares a servlet URL mapping, and exposes the action mapper used by its actions.

This example navigates through the configured HTTP controller to an HttpAction which returns a Component.

CODE
Button button = new Button("Open HTTP action");
button.onClick(new HttpActionOverview()
        .addParameter("name","JDance"));
RESULT

Parameters example

A parameterized request illustrates the same controller routing to an action with different request data.

CODE
Button button = new Button("Open parameter example");
button.onClick(new HttpActionParameters()
        .addParameter("name","Documentation"));
RESULT

How it works

CODE
public class HttpActionOverview extends HttpAction{
    @Override
    public void init(){
        setActionMapper(HttpControl.instance.getActionMapper());
    }

    @Override
    public Component perform(HttpContext context) throws Exception{
        String name = context.getRequest().getParameter("name");
        return new Text("Hello " + name);
    }
}

HTTP request parameters

Use a request parameter to control the response. An HttpAction returns a Component rather than a PushAction.

CODE
String name = context.getRequest().getParameter("name");
return new Text("Hello " + name);

Design guidance

Keep URL mapping and request-wide behavior in the controller. Keep page-specific behavior in actions. Controller hooks can be used for authentication or initialization.

Full API reference

These examples introduce the most important behavior without attempting to document every method. For the complete reference, see https://doc.jdance.org.