A "Hello World" app for the JHS (J HTTP Server) in J701 (Beta)
Just to record my current understanding of the sort of app which JHS lets you write, in the hope it might help others get started quickly, here is my attempt at a trivial "Hello World" app for JHS (the J HTTP Server) in its present form.
Download: hello.ijs
What it contains:
NB. Hello World app for JHS NB. updated: Sat 06 Nov 2010 05:50 IanClark NB. Run this script to create the locale: 'hello' NB. then seek URL: http://127.0.0.1:65001/hello (May need to Refresh Page) coclass'hello' NB. needed to create locale: 'hello' coinsert'jhs' NB. needed for jhs wds: jhr, NB. sentences to create html body NB. jhbshtml_jdemo1_'' shows HBS html HBS=: 0 : 0 'Hello World' ) NB. create html page from HBS CSS JS NB. HBS body can have TAGS that are replaced create=: 3 : 0 'hello'jhr'RESULT';y NB. <RESULT> tag replaced by y ) NB. called when browser gets this page jev_get=: create CSS=: '' NB. styles (none) JS=: '' NB. javascript (none)
How to use it
1. Start J701 using the JHS IDE
2. Enter: load '~user/hello.ijs'
This will create a locale: hello.
3. Open a new browser tab and enter the URL: http://127.0.0.1:65001/hello
- This will run the app, showing a very simple page (if you don't see it, press the browser's "refresh page" button):
Hello World
4. Study jdemo.ijs which comes as part of the JHS addon, to see how to elaborate this example.
How it works (I think...)
When the J server gets the URL, it looks for and runs jev_get'' inside the locale: hello.
If there is no such verb then the following message is output to the jijx session:
|value error: jev_get_hello_ | jev_get_hello_'' *** response not sent for hello *** html404 (URL not found) sent
...but you might have to enter an empty line in jijx before you see it.
jev_get_hello_ (jev_get inside the locale: hello) is typically assigned a verb always called: create which creates and sends the HTML page in response to the URL.
Verb jhr (in locale jhs), called by: create, creates the HTML of the page.
It takes a left arg: the page title (which usually appears in the browser tab). Its right arg is a specification to replace tags, eg <REPLACE>, which is shown here but unused in this simple example.
To do this, jhr makes use of three nouns:
HBS containing the page layout in a symbolic form (see jdemo.ijs examples)
CSS containing any special styles needed
JS containing any javascript code needed
In the present case HBS is a very simple layout, and both CSS and JS are set to ''
Scripts jdemo.ijs and the scripts that go with it, notably jdemo4.ijs, have examples of non-trivial CSS and JS.
If you haven't installed the J701 Beta, you can download this script here (for visual inspection only of course, because it won't usefully run under J602):
Download: jdemo4.ijs
-- IanClark 2010-11-06 05:50:58
