Documentation * What's New * FAQ * Download * Frink Applet * Web Interface * Sample Programs * Frink on Android * Donate
Frink Server Pages allows you to embed snippets of Frink code into an HTML document to give your web applications all the power of Frink. The server processes the Frink code quickly and delivers interactive applications with very little coding. It's similar to other server-side technologies as Active Server Pages, Java Server Pages, Cold Fusion, or PHP. But, being Frink, it's even more fun, and you can often write your program even more concisely and powerfully.
The following are simple applications to test Frink functionality, and to show you what FSP code looks like. The Frink code in each example is highlighted by a Frink Server Page. In most examples, the majority of the file is just HTML.
Frink Server Pages are based on the Java Servlet API. If you have a web
server that can run Java Servlets, you can run Frink Server Pages. Just
install the frink.war file
(or frink-tng.war if you want to
use Frink: The Next Generation) into your
web server. (See your server's documentation for required steps. You may
want/need to rename it fsp.war
when placing it into your web
server's webapps directory.)
In the .war
file's web.xml
file, there's a
fsp-root
initialization parameter indicating where Frink
Server Pages should be loaded from. You'll probably need to modify this.
(Hint: A .war
file is just a .jar
file
which is just a .zip
file. Unzip it, edit whatever you need
to, and either re-zip it or just put the files in the appropriate place on
your webserver.)
Embedded into your HTML, you add simple tags that surround Frink code. These tags are interpreted and removed by the server before the HTML is sent to the client. The client only sees normal HTML.
The print[]
and println[]
commands, when used in
an FSP page, print to the web server's output stream. Tags are processed
from top to bottom.
The tags <% %>
surround an
arbitrary block of Frink code. The following prints the numbers from 1 to
10 in the client's browser:
As a shortcut, the tags <%= %>
(note that
equals sign) evaluate an expression and print its value into the server's
output at that point.
Alan was born
<%= now[] - #1969-08-19 04:54 PM Mountain# -> "days" %>
ago.
In your HTML, you can precede a variable name with a dollar sign
($
) and it
will be replaced with its value. For example, if the variable
name
contains "Kotter"
, the
following will display the name right in the HTML document. This saves a
couple of keystrokes, and possibly improves speed and readability.
<P>Welcome back,
$name
!</P>
If you need to indicate where the variable name ends, or if your variable
name contains Unicode escapes like \u210f
for the
the micro prefix µ, you must enclose the whole variable name in curly
braces, like ${name}
.
Since a variable name must begin with a letter, it's fine to put a quantity
like $2.00
into the string, and no substitution will be
attempted, and there will be no runtime performance penalty. To put a
literal dollar sign into the string immediately preceding an alphabetic
character, use two dollar signs:
In Frink Server Page:
"I want my $$USD 2.00. Plus tip."
Produces output:
I want my $USD 2.00. Plus tip.
For best performance, don't use double dollar signs like this unless they directly precede a letter character.
For now, input from web forms is placed into a variable with the same name as the form field. If the variable has a single value, the variable will contain a single string. If the variable has multiple values, the variable will contain an array of strings.
To support internationalization and flexibility, Frink uses Unicode throughout.
Frink Server Pages are sent out with default charset=UTF-8
encoding. This should allow display of all Unicode characters without any
work on your part if your browser and font support it.
As anywhere in Frink, you may use Unicode escapes like
\u210f
anywhere in the HTML page or in Frink
variable names and identifiers, or in quoted strings.
You may need to set some directives to control the output of the page.
Directives should be at the beginning of the document and are enclosed in
<%@ %>
brackets and consist of name="value"
pairs. The current
parameters are:
contentType | The MIME type of the output, e.g.
"text/html" (the default)
or "text/plain" . Do not include the charset= attribute here; specify that with
pageEncoding .
|
pageEncoding | The output encoding
that will be used when creating the output stream. This can be any
character set encoding that your version of Java supports, e.g.
"UTF-8" (the default) or "ISO-8859-1"
|
persistent | If set to "true" (quotes are
required,) variables will persist across invocations of the page for the
session.
|
A page that supports wireless Palm VII devices must begin with the following:
<%@ contentType="text/html" pageEncoding="ISO-8859-1" %>
Frink Server Pages can render graphics that will be sent to the browser on demand. These graphics are rendered in memory, without the need for saving temporary image files on your web server (which fill up drives, and need to get cleaned up, and may never be requested, etc.)
There are only a few simple things to remember when rendering graphics:
contentType
to the MIME type
of the image you're going to send, for example contentType="image/png"
.
pageEncoding="raw"
to send out bytes without
modification. This is also necessary for rendering to SVG or HTML5,
which will actually be sent out with a UTF-8 encoding! Your
directives block may look like:
<%@ contentType="image/png" pageEncoding="raw" %>
graphics
object. See the Graphics section of
the documentation for details on how to draw graphics.
graphics.writeFormat["-", format, width,
height]
. For example:
g.writeFormat["-", "png", 1000, 600]
Make sure that the format you're rendering to matches the contentType
declaration sent out earlier! The "-"
renders its output directly to the data stream
going to the browser, instead of to an image file.
<% %>
block!
The following complete FSP page demonstrates rendering a black circle. Perhaps you can come up with something more clever.
<%@ contentType="image/png" pageEncoding="raw" %>
<%
g = new graphics
g.fillEllipseCenter[0,0,1,1]
g.writeFormat["-", "png", 600, 600]
%>
The numberCheckerboard.fsp sample program demonstrates drawing a random checkerboard. See its output.
Comments/questions to Alan Eliasen