product description
support resources and links download
We are sorry but we discontinued Websh support and development for lack of resources. Also the discussion mailing list was closed, so if you're interested in taking up this subproject within the Apache Tcl project to bring it back into life please contact private@tcl.apache.org

Websh example code

This section presents a selection of sample Websh applications. All applications are described in detail on this page and come with richly documented source code. For simplicity, they are all-in-one files. Plus, they are on-line and ready to use. For each application discussed below, you will find the corresponding links which present the styled code and the plain text version for download.

1 Table of Contents

Table of Contents

hello world

command dispatching


confirmation form

checkbox form

upload file



10 memory game

2 hello world

In order to get a first impression, let's look at a simple example. All it does is printing "Hello, world". It consists of one websh command, web::put. Basically, web::put works like Tcl's puts command. In addition to printing the text, it does send HTTP headers when invoked for the first time.
source | download

3 command dispatching

Now, let's look at one of the main features of websh: the command dispatching. This allows you to produce all your HTML page from one and the same source code. This example produces two HTML pages, the "greetings" page and a "price list" page (even though, for simplicity, the price list is empty). It uses web::dispatch to switch into one of these pages, and web::cmdurl to produce URLs pointing to each of these pages.
source | download

4 image

This example demonstrates how to return an image instead of the normal "text/html" mime type.
source | download

5 confirmation form

This example demonstrates a confirmation form. The user is promted a form to enter, say, order information. The information is validated and, if sucessfull, an e-mail is sent back to the user.
source | download

6 checkbox form

This example demonstrates how to handle checkboxes. The user is promted a form to select checkboxes, to display date informations.
source | download

7 upload file

This example demonstrates a upload form. The user is promted a form to enter, local file. The file is validated and, if sucessfull, the server shows in a confirmation the uploaded data back to the user.
source | download

8 sessions

This example demonstrates file-based server-side sessions. Suppose a customer visits this application for the first time. The application creates a new session file using state::init and stores the session id in the query string. From now on, state::init will know the session id and re-load the session context - the application "remembers" the customers settings across multiple HTTP requests using a session id embedded in all generated URLs. For simplicity, we do not add shopping items to a shopping cart in this example, but just save the data of two forms which are presented to the customer. This involves a little bit of form handling, and this example also demonstrates error handling in case of unexpected input. But let's look at the example.
source | download

9 cookie

This example demonstrates how to use cookies. It is very similar to the session example above.
source | download

10 memory game

This is a more complex example. You know the game "memory", right ? The goal is to find matching pictures with the least possible number of tries. The application keeps track of the number of your tries for a given game and level and compares it with the "hall of fame". This version does not use sessions except for the "hall of fame", and stores all information in the URL, which makes the output a little bit bulky. Have fun.
source | download

description | documentation | support | resources | download | credits | copyright

© Websh - an Apache Tcl project - part of the Apache Software Foundation