JSSP["JavaScript Server Pages"] = keeping.simple.things.simple;

JSSP - JavaScript Server Pages Tutorial

Home   Downloads   JSSP Docs   JSSQL Docs   Dervish Docs   License   Examples   Feedback

JavaScript Server Pages is a Java runtime library to execute JavaScript on a web server similar to ASP, PHP or JSP. It requires a web server that can run Java Servlets (such as Tomcat, JBoss or others).

This tutorial helps you to get started with JSSP.

Any comments and bug reports are highly appreciated by leo_meyer@users.sourceforge.net!

Bug reports, feature requests and forum posts can be submitted on the JSSP Project Page.

Note: This document uses Google's code prettifier. In Internet Explorer you may get warning messages about active content. You can safely allow active content or simply ignore these messages.

Table of Contents

Installing Java
Installing and configuring Tomcat
Downloading and installing the JSSP example application
Experimenting with the jssp-example scripts
Using MySQL as an external database
Installing MySQL
Configuring the jssp-example to use MySQL
More information
External documentation


This tutorial walks you through the steps necessary to deploy and modify the jssp-example application and tells you how to setup and connect a MySQL database to JSSP.

Installing Java

Download a recent Java Development Kit (JDK) from http://java.sun.com/javase/downloads/index.jsp.
On Linux you can also use sudo apt-get install gij or use the setup tool of your choice.

It is recommended that you use the most recent Java version available.

Install Java using the default settings. Set the environment variable JAVA_HOME to the root folder of your JDK installation (not the JRE folder that may also have been installed).

Installing and configuring Tomcat

Download a recent Tomcat version from http://tomcat.apache.org. Instructions for installation are provided on the same web site.

In the conf folder of your Tomcat installation there's a tomcat-users.xml file. Open the file in a text editor and add the following lines to the <tomcat-users> section:

<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="mypassword" roles="admin,manager"/>

This defines a user "admin" that has access to the administration application.

Start Tomcat (startup scripts reside in the bin folder) and point your browser to http://localhost:8080/manager/html. Login with user "admin" and password "mypassword". You should see the list of currently installed applications.

Note that for Linux installations the HTML administrator sometimes comes in a separate package, so be sure to install that as well.

Downloading and installing the JSSP example application

An example web application (jssp-example.war) is available for download at the download section. Save it to a folder of your choice.

Deploy the local jssp-example.war file to your Tomcat (bottom section of the web application page). This installs the JSSP example application:

Tomcat jssp-example.war installation

Click on the link /jssp-example in the list. You should see the JSSP welcome screen.

Experimenting with the jssp-example scripts

The jssp-example application contains a number of scripts that demonstrate some features of JSSP. The database examples use the in-memory database HSQLDB, so there's no need to install an external database. However, when you stop the application, the data is lost. The section below explains how to connect an external database to JSSP.

Tomcat automatically unpacks the .war file on deployment. The jssp files extracted from the .war file are located in the webapps/jssp-example folder below your Tomcat installation. Have a look at the source; you can also examine the generated jsspi files that contain the intermediate code. Modified jssp files will be executed when you reload the page; thus you can experiment with the source code to get a feeling for JSSP. There are also some example libraries under WEB-INF/jssp that might be interesting to play with.

Note that when you re-deploy the .war file any changes to the already deployed files are overwritten.

Using MySQL as an external database

Installing MySQL

Download a recent MySQL installation from http://www.mysql.org and install it. Connect to the database with the administration tool of your choice (for example, MySQL Administrator).

Create a MySQL database catalog named "jssp". Create a user "mysql" with password "mysql" and give this user full permissions on the jssp catalog.

Configuring the jssp-example to use MySQL

The example download already contains the necessary driver to connect Java to MySQL. All you need to do is activate the MySQL data source in the configuration file jssp.xml and modify the files dbtest.jssp and dbmeta.jssp to use a different data source.

First, edit the file WEB-INF/jssp.xml. Uncomment the following lines:

	<param name="url" 

In the dbtest.jssp and dbmeta.jssp files change the assignment of the data source:

//	var datasource = pooledHsqldb;
	var datasource = mysqldb;

In the dbtest.jssp file modify the table creation script for MySQL (around line 40; comment the line for HSQLDB and uncomment the line for MySQL with "--"):

-- the ID column must be defined differently for different database types

Save and reload the page in your browser to test the database connection.

Note: If you re-deploy the jssp-example application the changed files will be overwritten.


You have successfully installed and run your first JSSP application. Now it's time to move on and write your own!

The next section provides you with links to more information. Have fun!

More information

JSSP Description and Reference

JSSQL Description and Reference


External documentation

Douglas Crockford's JavaScript Pages (highly recommended)

JavaScript (ECMA-262, ECMAScript) Language Specification (tough stuff!)

Rhino JavaScript Project Home Page

JSqlParser Project Home Page

Document version: 0.2, 2007-05-24. Author: Leo Meyer, leo_meyer@users.sourceforge.net

This file is a part of the JSSP project documentation at http://jssp.sourceforge.net.

The JSSP project is hosted by Sourceforge. SourceForge.net Logo