JHP syntax is similar to ASP or PHP. Plain HTML is entered as is. J code
is introduced by matching pairs of percent brackes <% ... %>
.
As a result, plain text is sent to the server as is and the J code
is executed.
The web server is configured to recognize files with
.jhp
extension as JHP script and process them within
the JHP framework.
Any output in a particular piece of code is sent
in between the surrounding plain HTML. Two verbs are used for output:
print
and println
, the latter adding
a LF to the end. These verbs format arguments as string.
Output is produced by streaming into stdout
with 1!:2&4
. Besides text output, the stdout
file handle 4
is also used for binary output, as in
data writebmp 4
.
<%= ... %>
is a short cut for
<%print ... %>
. The content between such brackes
cannot contain new lines, where as the regular brackets permit them,
as in J script.
It is required that the first line of the page specifies the MIME format, such as
<% ContentType'text/html' %> <html><head> ...
It is possible to produce any format output, such as XML, CSV, images, audio, etc. However, attention has to be payed to observe spaces or absense thereof between the percent brackets.
If the whole file is a single script block without intermittent
verbatim (HTML) output, the surrounding <% ... %>
can be omitted. More specifically, special procesing of the percent
barackets is used only if the first two characters of the file are
"<%
", otherwise it is treated as a plain J script.
The latter is convenient for a hanlder scenario, i.e. script
that generates specific output format, such as a bitmap image.
However, ContentType
is still required as a first line.
HTTP GET parameters are obtained from the standard environment
variable 2!:5 'QUERY_STRING'
. A utility verb
qsparse
returns two column table of boxed names
and values.
A pseudo-folder '~CGI'
refers to the folder
containing current request script. It can be used in file
operations, such as jpath
, load
, etc,
to access resources from the web folder.
For example, load '~.CGI/util/common.ijs'
will fetch a script
from a sibling folder. Other user and J library scripts
are available from usual standard locations within J folder
hierarchy, regardless of the location of the web folder.