WikiWebServer.org

This is the mobile format for this page.
Page formats: [ secure | mobile | normal ]

Navigation menu

Development Tips

Returning basic content

Implement the HTTPResponder interface and return the Object, such as a String, that you want to display to visitors.public class MyTestPage implements HTTPResponder {
  respond(HTTPHandler conn) {
    return "HelloWorld!";
  }
}

Valid response types include byte[], String, BufferedImage and HTTPException.

Returning a templated page

Extend the TemplatedPage class to return a formatted HTML page.public class MyTestPage extends TemplatedPage implements HTTPResponder {
  generate() {
    setTitle("HelloWorld");
    append("HelloWorld");
  }
}

Get help writing HTML

Add a static import for HTMLHelper to format pages without wrting HTML.append(h(1 "This is a large heading"));
append(p("This is a paragraph."))
append(image("image.jpg"))
append(a("http://www.google.com/", "A link to google"))
append(form(textfield("name", name) + br() + submitButton("action", "Save")));

Reading form data

Headers and form data sent from the browser can be read from the HTTPRequest.// Read where the visitor came from
Map<String, String> reqHeaders = conn.getRequest().getHeaders();
String referer = reqHeaders.get("Referer");

// Read the input field named "name" sent from the browser
Map<String, String> formData = conn.getRequest().getFormData();
String sentText = formData.get("name");

Specify the content type

The default content type is text/html. The content type, and otherresponse headers can be specified in the HTTPResponse.

Map<String, String> resHeaders = conn.getResponse().getHeaders();
resHeaders.put("Content-Type", "application/rss+xml");

Store persistent data

WikiMaps provide a thread-safe, persistent key-value mapping for storing data and sharing between connections.// Read an object from MyDataStore with the name MyDataName
Object obj = WareHouse.getWikiMap("MyDataStore").get("MyDataName");

// Put the current date into MyDataStore, with the name LastAccessed
long dateTime = System.currentTimeMillis();
WareHouse.getWikiMap("MyDataStore").put("LastAccessed", dateTime));

// Put the number 27 into Age, within Mike, within UserDetails
WareHouse.getWikiMap("UserDetails", "Mike").put("LastAccessed", 27);

Only immutable objects can be put into WikiMaps with the exception of inner WikiMaps which facilitates a tree structure of data.