Servlet environment settings
The development environment is where you can develop, test, and run Servlets.
Just like any other Java program, you need to compile the Servlet by using the Java compiler javac After compiling the Servlet application, deploy it in the configured environment for testing and running .
If you are using the Eclipse environment, you can directly refer to: Eclipse JSP/Servlet environment construction.
This development environment setup 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 the SDK from Oracle's Java website: Java SE Downloads.
Once you download the SDK, follow the given instructions to install and configure the settings. Finally, set the PATH and JAVA_HOME environment variables to point to the directories containing java and javac, typically java_install_dir/bin and java_install_dir respectively.
If you are running Windows and installed the SDK in 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 also right-click "My Computer", select "Properties", and then select "Advanced", "Environment Variables". Then, update the value of PATH and press the "OK" button.
On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.5.0_20 and you are using the C shell, you need to put in your .cshrc file The following lines:
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, Integrated Development Environment), such as Borland JBuilder, Eclipse, IntelliJ IDEA or Sun ONE Studio, compile and run a simple program to Verify that the IDE knows the path to your Java installation.
Set up the web server: Tomcat
There are many web servers on the market that support Servlets. Some web servers are free to download, and Tomcat is one of them.
Apache Tomcat is an open source software implementation of Java Servlet and JavaServer Pages technology. It can be used as an independent server for testing Servlets and can be integrated into the Apache Web server. Here are the steps to install Tomcat on your computer:
Download the latest version of Tomcat from http://tomcat.apache.org/.
Once you download Tomcat, unzip it to a convenient location. For example, if you are using Windows, extract to C:\apache-tomcat-5.5.29, if you are using Linux/Unix, extract to /usr/local/apache-tomcat-5.5.29 , and create a CATALINA_HOME environment variable pointing to these locations.
On Windows, you can start Tomcat by executing the following command:
%CATALINA_HOME%\bin\startup.bat 或者 C:\apache-tomcat-5.5.29\bin\startup.bat
On Unix (Solaris, Linux, etc.), you can execute the following command. Start Tomcat:
$CATALINA_HOME/bin/startup.sh 或者 /usr/local/apache-tomcat-5.5.29/bin/startup.sh
After Tomcat starts, you can access the default applications in Tomcat by entering http://localhost:8080/ in the browser address bar. If all goes well, the following results will be 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 CLASSPATH
Since Servlet is not part of the Java Platform Standard Edition, So you must specify the path to the Servlet class to the compiler.
If you are running Windows, you will need to put the following lines in your C:\autoexec.bat file:
set CATALINA=C:\apache-tomcat-5.5.29 set CLASSPATH=%CATALINA%\common\lib\servlet-api.jar;%CLASSPATH%
Or, in Windows NT/2000/XP, You can also right-click "My Computer", select "Properties", then select "Advanced", "Environment Variables". Then, update the value of CLASSPATH and press the "OK" button.
On Unix (Solaris, Linux, etc.), if you are using the 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), then you also need to add these directories to CLASSPATH in a similar way to the above.