JSP Development Environment Setup
JSP development environment is where you develop, test, and run JSP programs.
This section will guide you through setting up a JSP development environment, including the following steps.
If you are using the Eclipse environment, you can directly refer to: Eclipse JSP/Servlet Environment Setup.
Configure Java Development Kit (JDK)
This step involves downloading the Java JDK and configuring the PATH environment variable.
You can download the JDK from Oracle's Java page: Java SE Downloads
After downloading the Java JDK, please follow the given instructions to install and configure the JDK. Finally, set the PATH and JAVA_HOME environment variables to point to the folders containing java and javac, typically java_install_dir/bin and java_install_dir.
If you are using a Windows system and the JDK installation directory is C:\jdk1.5.0_20, then you need to add the following two lines in the C:\autoexec.bat file:
set PATH=C:\jdk1.5.0_20\bin;%PATH%
set JAVA_HOME=C:\jdk1.5.0_20
Alternatively, on Windows NT/2000/XP, you can directly right-click the My Computer icon, select Properties, then Advanced, then Environment Variables, and then you can easily set the PATH variable and confirm to exit.
On Linux/Unix systems, if the JDK installation directory is /usr/local/jdk1.5.0_20 and you are using the C shell, then you need to add the following two lines in the .cshrc file:
setenv PATH /usr/local/jdk1.5.0_20/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.5.0_20
Alternatively, if you are using an integrated development environment like Borland JBuilder, Eclipse, IntelliJ IDEA, and Sun ONE Studio, you can try compiling and running a simple program to determine if the IDE already knows the JDK installation directory.
You can also refer to the tutorial in this site's Java Development Environment Configuration section for this step.
Set Up Web Server: Tomcat
Currently, there are many web servers that support JSP and Servlets development. Some of them can be downloaded and used for free, and Tomcat is one of them.
Apache Tomcat is an open-source software that can run as a standalone server for JSP and Servlets or be integrated into the Apache Web Server. Here is how to configure Tomcat:
Download the latest version of Tomcat: http://tomcat.apache.org/.
After downloading the installation file, unzip the compressed file to a convenient location, such as the C:\apache-tomcat-5.5.29 directory on Windows or the /usr/local/apache-tomcat-5.5.29 directory on Linux/Unix, and then create a CATALINA_HOME environment variable pointing to these directories.
On a Windows machine, Tomcat can be started by executing the following command:
%CATALINA_HOME%\bin\startup.bat
or
C:\apache-tomcat-5.5.29\bin\startup.bat
On a Linux/Unix machine, Tomcat can be started by executing the following command:
$CATALINA_HOME/bin/startup.sh
or
/usr/local/apache-tomcat-5.5.29/bin/startup.sh
After successfully starting Tomcat, you can access Tomcat's built-in web applications by visiting http://localhost:8080/. If everything goes smoothly, you should be able to see the following page:
For more information on configuring and running Tomcat, you can find it in the documentation provided by Tomcat or visit the Tomcat official website: http://tomcat.apache.org.
On a Windows machine, Tomcat can be stopped by executing the following command:
%CATALINA_HOME%\bin\shutdown.bat
or
C:\apache-tomcat-5.5.29\bin\shutdown.bat
On Linux/Unix machines, Tomcat can be stopped by executing the following command:
$CATALINA_HOME/bin/shutdown.sh
or
/usr/local/apache-tomcat-5.5.29/bin/shutdown.sh
Setting the CLASSPATH Environment Variable
Since servlets are not part of Java SE, you must indicate the compiler for servlet classes.
If you are using a Windows machine, you need to add the following two lines to the C:\autoexec.bat file:
set CATALINA=C:\apache-tomcat-5.5.29
set CLASSPATH=%CATALINA%\common\lib\jsp-api.jar;%CLASSPATH%
Alternatively, on Windows NT/2000/XP, you can right-click My Computer, select Properties, then click Advanced, and then Environment Variables. From there, you can set the CLASSPATH variable and confirm to exit.
On Linux/Unix machines, if you are using the C shell, you need to add the following two lines to the .cshrc file:
setenv CATALINA=/usr/local/apache-tomcat-5.5.29
setenv CLASSPATH $CATALINA/common/lib/jsp-api.jar:$CLASSPATH
Note: If your development path is C:\JSPDev (Windows) or /usr/JSPDev (Linux/Unix), you need to add these paths to the CLASSPATH variable.