Complete control when printing HTML from an agent

Jake Howlett, 4 October 2000

Category: Agents; Keywords: Agent Print HTML

Agents that are run via the web can use the "Print" statement in order to dynamically write HTML back to the browser.

For example, in a Web Query Save agent you could return a message to the user to let them know everything went ok:

Print "<h2>Your document has been saved</h2><br />"
Print "Use this link to return to that page - <a href=""JavaScript: history.go(-2)"">Go Back 2 Pages</a>"


In the above example domino will start things off for you by creating the first few lines of necessary code. This usually starts off with the <html>, <head> and <body> tags.

If you want to have complete control over the HTML, say to set the title or the include some JavaScript in the HEAD, then the first line you print needs to be like below, which tell domino not to start the tags itself.

Print "Content-Type:text/html"


You can then carry on creating the HTML yourself.

Print "<html>"
Print "<head>"
Print "<title>"
Print "This is made ""dynamically"", by domino"
Print "</title>"

etc

Notice that in the above it is getting a bit tiresome having to use the Print statement as double quotes so often. To get around this use the curly braket delimters for you print string. This lets you use multiple line and no need to use double quotes when you want to include a single quote.

For example, the above example would be:

Print {
<html>
<head>
<title>
This is made "dynamically", by domino
</title>
.....
</body>
</html>
}


Notes:
You can also use the vertical bar | symbol.

You can do this is Java as well. First thing to do is import the "java.io" package. Then define a PrintWriter object and print lines to it:

import java.io.*;

PrintWriter pw = getAgentOutput();
pw.println("Content-Type:text/plain")
pw.println("Content-Type:text/html");