You are on page 1of 7

http://www.stardeveloper.com/articles/display.html?

article=2001060801&page=1

Installing, Configuring, & Running Tomcat 6.0 Servlet Container


on Microsoft Windows, and Developing & Running your first JSP
Page
by Faisal Khan.
Overview
In this article I'll introduce what is JSP and why at all do we need to learn it.
Then I'll move on to describe the installation of open source Servlet
Container/JSP Engine, Tomcat. Once done, I'll explain the steps of running
your first JSP page. Note that I am not going to describe the structure of a
JSP page and what are the different features of JSP, I'll cover them in a
separate article.
What is JSP?
JSP stands for 'Java Server Pages'. These are pages which are used to serve
dynamic content to the user using logic and data (XML, Database etc) on the
server side. JSP is a part of J2SE (Java 2 Standard Edition) and along with
Java Servlets and Java Beans is used to develop efficient, scalable and
secure web applications in quick time.
Why bother with JSP when ASP is already here?
Nice question, first of all ASP is not the only solution out there which
supports rapid web application development, there are others like PHP, Perl,
ColdFusion etc. JSP is different from all of them because :

• JSP uses Java. Java is by far one of the most popular programming
languages on the web. Its simpler syntax and 'write once run anywhere'
capability makes it THE server side programming language of choice. So JSP
pages and Java applications that you create will run on almost all major
operating systems e.g. Windows, UNIX, Mac etc. You don't need to create
separate apps for separate platforms.
• JSP is part of J2EE. J2EE (Java 2 Enterprise Edition) is one of the most
popular models used to develop Enterprise level applications. J2EE is
supported by software giants like Sun Microsystems, BEA, Oracle, IBM etc.
So once you learn to program JSP, you can extend your skills to learn other
Java technologies to become what is called, an Enterprise Software
Developer.
• Networking is built into Java. Java's inherent support for networking
makes it an ideal langauge for the internet.
I can continue to write more and more reasons as to why to use Java (JSP)
but then it will make my article longer than I would like, so I suffice with the
above features. Once you'll learn Java (JSP), you'll come to know what I
mean when I say 'Java is the best language for the internet'.

Continue reading to see the basic steps required in the installation of Tomcat
6.0 Servlet Container / JSP Engine. I'll be using Tomcat in the later articles
and tutorials on 'Server Side Java' so you need to have it installed on your
system.

Following is a list of topics we'll cover in this article :

• Introduction to JSP ( this page )


• Installing Tomcat 6.0
• Your first JSP page
• Summary

You'll need to have JDK 1.6 (or simply 'JDK 6', as it is called on Sun's
download page) installed on your system in order for Tomcat 6.0 to work
properly. If you don't already have it, you can get it from java.sun.com.

Obtaining Tomcat 6.0


Tomcat 6.0 is an open source and free Servlet Container and JSP Engine. It
is developed by Apache Software Foundation and is available for download at
http://tomcat.apache.org, or more specifically at
http://tomcat.apache.org/download-60.cgi. Choose the latest Tomcat 6.0
version. Currently Tomcat 6.0.14 is the latest version. Once you have
downloaded Tomcat 6.0, proceed to the next step.
Installing Tomcat 6.0
Unzip the file to a suitable folder. In Windows, you can unzip it to C:\ which
will create a directory like C:\apache-tomcat-6.0.14 containing Tomcat files.

Now you'll have to create two environment variables, CATALINA_HOME and


JAVA_HOME. Most probably you'll have JAVA_HOME already created if you have
installed Java Development Kit on your system. If not then you should
create it. The values of these variables will be something like :

• CATALINA_HOME : C:\apache-tomcat-6.0.14
• JAVA_HOME : C:\Program Files\Java\jdk1.6.0_03

To create these environment variables in Windows 2000 or Windows XP, go


to Start -> Settings -> Control Panel -> System -> Advanced ->
Environment Variables -> System variables -> New. Enter the name and
value for CATALINA_HOME and also for JAVA_HOME if not already there.

Under Windows 95/98, you can set these variables by editing C:\autoexec.bat
file. Just add the following lines and reboot your system :

SET CATALINA_HOME=C:\apache-tomcat-6.0.14
SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_03
Running Tomcat 6.0
Ok now, lets start Tomcat by running the C:\apache-tomcat-
6.0.14\bin\startup.bat batch file. Tomcat server will start and print some
status messasge. Now point your browser to http://localhost:8080 and you
should see the default Tomcat home page. To shutdown the server run
C:\apache-tomcat-6.0.14\bin\shutdown.bat batch file.
Go to C:\apache-tomcat-6.0.14\webapps\ folder and create a new directory
with the name of "star". You can give it any name you want but for this
example we'll stick with "star".

Now create a new file and save it as 'index.jsp' in the "star" directory
created above. Copy the following text into 'index.jsp' file and save it :

<html>
<head>
<style>p { font-family:tahoma; font-size:14pt; }</style>
</head>
<body>

<%
String name = "Faisal Khan";
%>
<p>Hello <%= name %>!</p>
</body>
</html>

Above page appears to be a simple HTML page except one line of Java code
between the <% and %> tags. These work the same way as <% %> tags in
ASP. You can add server side Java code between these tags. In this case we
simply declared a variable 'name' of type String ( simple text ) and initialized
it with a value of "Faisal Khan", you can substitute your own name if you
want.

<%
String name = "Faisal Khan";
%>

Next we display the value of 'name' variable to the user.

<p>Hello <%= name %>!</p>

Start Tomcat server and point your browser to


http://localhost:8080/star/index.jsp to see the JSP page running.

Summary
In this article I introduced JSP as a new, efficient, scalable and secure technology to develop
web applications. I then walked you through the steps of downloading and installing Tomcat
6.0.14. Tomcat is Java web container ( Servlet Container and JSP Engine ) available for free
from Apache Software Foundation. In the end we built and tested a simple JSP page
'index.jsp'.
@@@@@@@@@@@@@@@

http://www.roseindia.net/servlets/HowToRunAServlet.shtml

To run a servlet one should follow the steps illustrated below:

• Download and Install the tomcat server: Install the tomcat server in a directory
in which you want to install and set the classpath.for the variable JAVA_HOME in the
environment variable. To get details about the installation process and setting the classpath
click the link Tomcat installation.
• Set the class for the jar file: Set the classpath of the servlet-api.jar file in the
variable CLASSPATH inside the environment variable by using the following steps.

For Windows XP,

Go to Start->Control Panel->System->Advanced->Environment Variables->New


button and Set the values as
Variable Name: CLASSPATH
Variable Value: C:\Program Files\Java\Tomcat 6.0\lib\servlet-api.jar

For Windows 2000 and NT

Go to Start->Settings->Control Panel->System->Environment Variables->New


button and Set the values as
Variable Name: CLASSPATH
Variable Value: C:\Program Files\Java\Tomcat 6.0\lib\servlet-api.jar

• Create a java source file and a web.xml file in a directory structure.


• Compile the java source file, put the compiled file (.class file) in the classes folder of
your application and deploy the directory of your application in the webapps folder inside
the tomcat directory.
• Start the tomcat server, open a browser window and type the URL
http://localhost:8080/directory (folder name of your application) name/servler
name and press enter.

If everything is correct your servlet will run.

@@@@@@@@@@@@@@

http://tomcat.apache.org/download-60.cgi

Binary Distributions
• Core:

o zip (pgp, md5)


@@@@@@@@@@

http://localhost:8080/ravi/jsp/pro1.jsp

CATALINA_HOME :

D:\Documents and Settings\Ravi.RAVI-PC\Desktop\apache-tomcat-6.0.29\apache-tomcat-


6.0.29

JAVA_HOME : D:\Program Files\Java\jdk1.6.0

D:\Documents and Settings\Ravi.RAVI-PC\Desktop\apache-tomcat-6.0.29\apache-tomcat-


6.0.29\webapps\ravi\jsp\pro1.jsp

@@@@@@@@@@@@http://www.codingforums.com/archive/index.php/t-
114401.html
First, make sure that tomcat is currently running

Second, point your browser to http://localhost:8080

Once there, you will be able to set a default tomcat page. if you cannot see it...it could
be due to any of the following reasons:-
1- The port is not 8080
2- Tomcat is not currently running

if it is the first one...please go and locate the following file

C:\Tomcat\conf\server.xml

around line 76...see what is the port on your system...

<Connector port="8080" maxHttpHeaderSize="8192"


maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />

If you don't like adding port 8080...or http://localhost:8080 you can change it to
80...and then you can write http://localhost
Another important file...you should look at is the following
C:\Tomcat\conf\tomcat-users.xml
Well..if you want to access the Tomcat Manager...then you should add the following
two line
<role rolename="admin"/>
<user username="YOUR_USER_NAME_HERE" password="YOUR_PASSWORD_HERE"
roles="admin,manager"/>

As for seeing your project, depending on what you have called your project...you
should be able to see at http://localhost:8080/PROJECT_NAME

Cheers,
Ess