Lecture Slides

Download Report

Transcript Lecture Slides

Field Trip #24
Setting Up a Web Server
Apache





Apache is one of the most successful open
source web servers
In 1995 the most popular web server was the
HTTP daemon
Many webmasters had modified it and add fixes
to it (patches)
However, there was no way maintain a single
distribution that contained them all
A small group of webmasters were contacted
Apache, cont'd

They came up with a scheme to provide a way
that all of them could share their patches

That is why the server is name Apache

It is today the most popular web server
Tomcat




Tomcat is an open source implementation of the
Java Servlet technologies and JPS
technologies
A “servlet” is a small Java program that runs on
a server
It receives information through requests and
outputs information to the user
When you download Tomcat, it will come with
the jar files you will need in order to create
servlets
Connecting Apache to Tomcat



In order to connection Apache to Tomcat, we
will use a connector
When a request for a servlet is received,
Apache will forward that request to Tomcat
We must configure Apache so that it can
forward requests
This is the structure found in
c:\Program Files (x86)\Apache
Software Foundation\Apache2.2
The main configuration file for
Apache is httpd.conf
These are the extra files containing
optional configuration
The de facto port Apache uses is 80
All documents to be served out
should be placed in DocumentRoot
The default file that will be served
out is the DirectoryIndex
The error log is important
The Directory tags lets us specify if
users can access files
Apache seperates some
configuration files into the extra
directory and we can choose if we
want to include them
Tomcat

To install Tomcat, we unzip the file containing
Tomcat

We will extract this into c:\Users\Public\tomcat

C:\Users\Public is open to everyone

We also create a directory called connector
under tomcat, and there we place the file
mod_jk.so
These are the configuration files
found in tomcat\conf
This is found in tomcat-users
This is an important file. It creates a
worker that will be used to executes
the servlets we request
We have to modify the server
configuration file so that it uses the
same port specified in
worker.properties
This file allows us to connect Apache to
Tomcat. We load the connector, specify the
workers file, specify the log files, and mount
directories on the worker. This means that
requests for servlets in those locations is
passed to the worker
Creating a Basic HTML Page

We can use an editor like notepad to create a
basic html document

A simple document can start with an <html> tag

In the <head> section, we can specify the title

In the <body> section, we specify the content
Creating a Form




A form begins with the tag <form method=”post”
action=”action”>
We can include text fields for the user to input
information with the tag <input name=”name”
size=40>
We need to include at least one submit button
<input type=”submit” value=”Submit”>
We finish the form with </form>
Creating a Servlet



A Servlet is created by creating a subclass of
javax.servlet.HttpServlet
In this class, if we want to support the GET
method, we implement the doGet method
If we want to support the POST method, we
implement the doPost method
CLASSPATH



In order to compile the servlet, you need to
make sure that servlet-api.jar is in your
CLASSPATH
CLASSPATH is a list of directories that are
searched for classes
In order to include a jar in the CLASSPATH, you
list the absolute path including the jar file name
A Simple Servlet
The GET and POST Methods



The GET method allows you to access the
servlet with requests that look like
http://.../?name=x
The POST method allows you to access the
servlet as the request of a post and the
information is not visible
In order to access the query, you can use the
method getParameter that you call on an
HttpServletRequest object