JSP development environment setup


The JSP development environment is where you develop, test and run JSP programs.

This section will take you to set 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 construction.


Configuring Java Development Tools (JDK)

This step involves downloading the Java SDK and configuring the PATH environment variable.

You can download the SDK from Oracle's Java page: Java SE Downloads

After downloading the Java SDK, please follow the given instructions to install and configure the SDK. Finally, specify the folder path including java and javac by setting the PATH and JAVA_HOME environment variables, usually java_install_dir/bin and java_install_dir.

If you are using a Windows system and the SDK installation directory is C::\jdk1.5.0_20, then you need to add the following two lines to the C:\autoexec.bat file:

set PATH=C:\jdk1.5.0_20\bin;%PATH%
set JAVA_HOME=C:\jdk1.5.0_20

Or, under Windows NT/2000/XP, you can right-click the My Computer icon, select Properties, then Advanced, then Environment Variables. Then you can easily set the PATH variable and confirm to exit. .

Under Linux/Unix system, if the SDK installation directory is /usr/local/jdk1.5.0_20 and you are using C shell, then you need to add the following two lines to 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 whether the IDE (integrated development environment) Already know the SDK installation directory.

You can also refer to the tutorial in the Java development environment configuration chapter of this site for this step.


Set up the web server: Tomcat

Currently, there are many web servers on the market that support JSP and Servlets development. Some of them are free to download and use, Tomcat is one of them.

Apache Tomcat is an open source software that can be used as an independent server to run JSP and Servlets, or can be integrated into Apache Web Server. The following is the configuration method of Tomcat:

  • Download the latest version of Tomcat: http://tomcat.apache.org/.


  • After downloading the installation file, unzip the compressed file to a convenient place, such as C:\ apache-tomcat-5.5.29 directory or the /usr/local/apache-tomcat-5.5.29 directory under Linux/Unix, and then create the CATALINA_HOME environment variable to point to these directories.

Under Windows machines, Tomcat can be started by executing the following command:

%CATALINA_HOME%\bin\startup.bat
或者
C:\apache-tomcat-5.5.29\bin\startup.bat

Under Linux/Unix machines, Tomcat can be started by executing the following commands:

$CATALINA_HOME/bin/startup.sh
或者
/usr/local/apache-tomcat-5.5.29/bin/startup.sh

After successfully starting Tomcat, you can use some of the web applications that come with Tomcat by accessing http://localhost:8080/. If all goes well, you should be able to see the following page:

TomcatHomePage.jpg

More information about configuring and running Tomcat can be found in the documentation provided by Tomcat, or go to Tomcat Check the official website: http://tomcat.apache.org.

Under Windows machines, Tomcat can be stopped by executing the following command:

%CATALINA_HOME%\bin\shutdown
或者
C:\apache-tomcat-5.5.29\bin\shutdown

Under Linux/Unix machines, Tomcat can be stopped by executing the following commands:

$CATALINA_HOME/bin/shutdown.sh
或者
/usr/local/apache-tomcat-5.5.29/bin/shutdown.sh

Set the CLASSPATH environment variable

Since servlets are not part of Java SE, you must indicate the compiler for the servlet class.

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%

Or, under Windows NT/2000/XP, you only need to Right-click My Computer, select Properties, then click Advanced, then click Environment Variables. Then you can set the CLASSPATH variable and confirm to exit.

Under Linux/Unix machine, if you are using C shell, then you need to add the following two lines in 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), then you need to add these paths to the CLASSPATH variable.