WebTool provides an easy and efficient way to implement web based tools with Erlang/OTP. WebTool configures and starts the webserver and the various web based tools.
All tools that shall run under WebTool must have a *.tool
file in the code path or in its priv directory. When WebTool
starts it searches the code path for such files. For each
Start WebTool by calling the function
Use
WebTool, with the default configuration as in
Start WebTool and point the browser to the corresponding URL. At the top of the page there is a frame with a link named WebTool. Click that link and a page where it is possible to start the available tools will appear in the main frame.
Click on the link labeled WebTool in the topmost frame, select the checkbox for each tool to start and click on the button labeled Start. A link to each tool that WebTool succeeded to start will appear in the topmost frame.
Click on the link labeled WebTool in the topmost frame. Select Stop Tools in the left frame. Select the checkbox for each tool to stop and click on the button labeled Stop.
WebTool can be used as a framework when developing new web based tools.
A web based tool running under WebTool will typically consist of three parts.
In most cases it is a good idea to separate the code for creation of the html-pages and the code for the logic. This increases the readability of the code and the logic might be possible to reuse.
When WebTool starts it searches the current path for
{version,"1.2"}.
[{config_func,{Module,Function,Arguments}}].
The *.tool file points out a configuration function. This
function must return a list of configuration parameters (see
the Reference Manual for
The
If the tool requires any processes to run, the
The
Erl Scheme tries to resemble plain CGI. The big difference is that Erl Scheme can only execute Erlang code. The code will furthermore be executed on the same instance as the webserver.
An URL which calls an Erlang function with Erl Scheme can have the following syntax:
]]>
An
The following URL will then cause a call to the function helloworld:helloworld/2 (if WebTool is started with default settings i.e. servername "localhost" and port 8888):
Note that the module
Functions that are called via the Erl Scheme must take two
arguments,
An
See the INETS documentation, especially the module
A Hello World example that uses Erl Scheme would look like
this. Note that this example does not have a process running
and thus does not need a
helloworld.erl:
-module(helloworld). -export([config_data/0]). -export([helloworld/2]). config_data()-> {testtool, [{web_data,{"TestTool","/testtool/helloworld/helloworld"}}, {alias,{erl_alias,"/testtool",[helloworld]}}]}. helloworld(_Env,_Input)-> [header(),html_header(),helloworld_body(),html_end()]. header() -> header("text/html"). header(MimeType) -> "Content-type: " ++ MimeType ++ "\r\n\r\n". html_header() -> "<HTML> <HEAD> <TITLE>Hello world Example </TITLE> </HEAD>\n". helloworld_body()-> "<BODY>Hello World</BODY>". html_end()-> "</HTML>".
To use this example with WebTool a *.tool file must be created
and added to a directory in the current path, e.g. the same
directory as the compiled
testtool.tool:
{version,"1.2"}.
[{config_func, {helloworld,config_data,[]}}].
When