HttpContext

HttpContext gives an HttpAction access to its incoming HTTP request and outgoing response. It is passed into perform() by HttpController.

Overview

Use getRequest() to retrieve submitted parameters and getResponse() when response configuration is needed. Normal HTTP actions return a component for rendering.

This example navigates to a real action that reads a name parameter from HttpContext.

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

Parameters example

The second example sends a different name to the same kind of HTTP action, illustrating how request data influences the rendered response.

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

Treat request parameters as untrusted. A context represents the current request, so avoid retaining it in long-lived components or static fields.

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.