Servlet environment settings
The development environment is where you can develop, test, and run Servlet.
Like any other Java program, you need to compile Servlet by using the Java compiler javac, and after compiling the Servlet application, deploy it in a configured environment for testing and running.
If you are using Eclipse
environment, you can directly refer to: Eclipse JSP/Servlet environment building.
This development environment setting includes the following steps:
Set up the Java Development Kit (Java Development Kit)
This step involves downloading the Java Software Development Kit (SDK, or Software Development Kit) and setting the PATH environment variable appropriately.
You can download SDK from Oracle’s Java website: Java SE Downloads .
Once you have downloaded SDK, follow the given instructions to install and configure the settings. Finally, set the PATH
and JAVA_HOME
the environment variable points to the directory that contains java and javac, usually java_install_dir/bin
and java_install_dir
.
If you are running Windows and install SDK in the C:\jdk1.5.0_20
you need to put the following lines in your C:autoexec.bat file:
set PATH=C:\jdk1.5.0_20\bin;%PATH%
set JAVA_HOME=C:\jdk1.5.0_20
Alternatively, in Windows NT/2000/XP, you can right-click my computer, select Properties, and then select Advanced, Environment variables. Then, update PATH
and press the OK button.
On Unix (Solaris, Linux, etc.), if SDK is installed in the /usr/local/jdk1.5.0_20
and you are using C shell, you need to use it in .cshrc
, put the following lines in the file:
setenv PATH /usr/local/jdk1.5.0_20/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.5.0_20
Also, if you use an integrated development environment (IDE, that is, Integrated Development Environment), such as Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, compile and run a simple program to verifythat the IDE knows the Java path you installed.
For more details, please see: Java Development Environment configuration
Set up Web Application Server: Tomcat
There are many Web application servers on the market that support Servlet. Tomcat is one of some Web application servers that are downloaded for free.
Apache Tomcat is an open source software implementation of Java Servlet and JavaServer Pages technology, which can be used as a stand-alone server for testing Servlet and can be integrated into Apache Web application servers. Here are the steps to install Tomcat on your computer:
Download the latest version of Tomcat from http://tomcat.apache.org/.
Once you have downloaded Tomcat, unzip it to a convenient location. For example, if you are using Windows, extract it to
C:\apache-tomcat-5.5.29
if you are using Linux/Unix, extract it to/usr/local/apache-tomcat-5.5.29
and createCATALINA_HOME
the environment variable points to these locations.
On Windows, you can start Tomcat by executing the following command:
%CATALINA_HOME%\bin\startup.bat
or
C:\apache-tomcat-5.5.29\bin\startup.bat
On Unix (Solaris, Linux, etc.), you can start Tomcat by executing the following command:
$CATALINA_HOME/bin/startup.sh
or
/usr/local/apache-tomcat-5.5.29/bin/startup.sh
After Tomcat starts, you can access the default application in Tomcat by entering http://localhost:8080/ in the browser address bar. If all goes well, the following results are displayed:
Further information on configuring and running Tomcat can be found in the documentation for the application installation, or you can visit the Tomcat website: http://tomcat.apache.org.
On Windows, you can stop Tomcat by executing the following command:
C:\apache-tomcat-5.5.29\bin\shutdown
On Unix (Solaris, Linux, etc.), you can stop Tomcat by executing the following command:
/usr/local/apache-tomcat-5.5.29/bin/shutdown.sh
Set up CLASSPATH
Because Servlet is not part of the standard edition of the Java platform, you must specify the path of the Servlet class for the compiler.
If you are running Windows, you need to use the C:\autoexec.bat
put the following lines in the file:
set CATALINA=C:\apache-tomcat-5.5.29
set CLASSPATH=%CATALINA%\common\lib\servlet-api.jar;%CLASSPATH%
Alternatively, in Windows NT/2000/XP, you can right-click my computer, select Properties, and then select Advanced, Environment variables. Then, update CLASSPATH
and press the OK button.
On Unix (Solaris, Linux, etc.), if you are using C shell, you need to put the following lines in your .cshrc file:
setenv CATALINA=/usr/local/apache-tomcat-5.5.29
setenv CLASSPATH $CATALINA/common/lib/servlet-api.jar:$CLASSPATH
Note: assuming that your development directory is C:ServletDevel (on Windows) or / user/ServletDevel (on UNIX), you also need to use the CLASSPATH
add these directories in a manner similar to the one above.