Part A: Installing Blazix
and running the Web Server
Download the Blazix web server from here
. Install the web server onto
your u: drive. We need to change the port that the web server is run
ning on from 80 to 8082, in
order to prevent any conflicts with Oracle which is running on port 80 in some of the labs. To do
so, open the web.ini file in the u:
blazix directory and change the server.port number on the third
line to 8082.
web server by executing blxweb.cmd in your Blazix folder. The webfiles folder in the
Blazix folder is the directory that stores all the files to be served by your web server. Delete all
files currently located there and insert a single text file named ind
ex.html containing some plain
text. (You may wish to format your text so that it is displayed as HTML).
Point your browser to http://localhost:8082/ and you will see your default page being served.
You can change the URL so that it uses your IP addr
ess (which you can find out using ipconfig
at the command prompt), so that your URL is now http://147.252.001.123:8082/ or something
similar. You can also use your host name instead of your IP address. Using this, view the pages
being served by your neighb
You can put more pages and subdirectories in your webfiles folder, which can then be viewed
using the full path:
Running a servlet
We are now going to create your first servlet
. To compile you must
include the Blazix.jar file in your classpath, as this contains the required classes. You should
redirect your compiled cla
ss to the classes directory on your web server, as this is where Blazix
will look for them:
Edit your web.ini file in your Blazix folder
this contains information o
n all your servlets. Put
the following lines at the end of the file:
The first line identifies the name of your servlet, the second line shows which compiled class
rvlet uses, and the third line gives the URL of the servlet
note, these do not need to be
called "first", they can be given any name, once the same name is used in the HTML form.
Stop and restart your web server so it can pick up the new web.ini. Y
ou can stop your server by
C in the DOS window opened up for Blazix. Restart by executing blxweb.cmd.
(Right Click, and S
ave Target As) and save it in your
folder. Then direct your browser to http://localhost:8082/FirstServlet.html.
This give you a HTML form which you can use to send information to your server side servlet.
note how the form in the HTML s
ource code gives the relative URL of the servlet to be executed
as the action attribute. Click on the button to see the servlet running.
Repeat steps 5
(remember to download with
> Save Target As). Remember to put the following files in your web.ini file.
The following example uses three servlets to make a shopping cart example.
as well as the HTML
Each servlet must be registered separately, as given below:
Restart the server.
Notice how state is maintained between each of th
e three servlets using the built in sessions.
Cookies allow state to be maintained for longer than normal sessions. In this example we want to
maintain a set of user preferences for longer than a single session
rs their name and preferred colours, they are written to a cookie. This information can
then be retreived from the cookie at a later date. This is how web applications like hotmail
remember who you are when you log in.
as well as the HTML
Register each of the servlets, as shown here:
Restart the serve
Notice how the state is maintained even after a session has ended
to see this use the
application, close your browser and start again. You will not be prompted for your preferences a
and extract the contents to the webfiles directory in your Blazix folder. Start
Blazix and direct your browser to http://localhost:8082/SimpleAdderX.html. Examine the code
to see how it differs from the s
Note that JSP
such as Adder.jsp
are just quick ways to write servlets
they are still compiled
with their classes going to the jspdir folder. All the objects available in the servlets (session,
request, response, out and others) are i
mplicitly available in the JSP.
shows how Java code can be used to read data from URL with
HTTP GET using the Java HTTP classes.
this out with the following:
:/> java ReadFromURL http://www.comp.dit.ie
:/> java ReadFromURL http://dictionary.reference.com/search?q=java
shows how to pass arguments to a servlet, or any HTTP server
side application using POST.
Try it out by creating a servlet/JSP that uses POST and then running:
:/> java SendToURL http://localhost/my_servlet a=arg1 b=arg2 c=arg3