Often see the JSP novice ask Tomcat How to configure the JSP, servlet and bean issues, so summed up how to configure the JSP, Servlet and Ben, in the hope of helping those beginners.
I. Development environment Configuration
Step one: Download J2sdk and tomcat: Download J2SDK to the Sun official station (HTTP://JAVA.SUN.COM/J2SE/1.5.0/DOWNLOAD.JSP), note that the download version is Windows Offline Installation SDK, it is also best to download J2SE 1.5.0 documentation and then to the Tomcat official site (http://jakarta.apache.org/site/downloads/downloads _tomcat-5.cgi) Download tomcat (download the latest 5.5.9 version of Tomcat);
Step Two: Install and configure your J2SDK and Tomcat: Perform J2SDK and tomcat setup, and then install it by default settings.
1. After installing J2SDK, you need to configure the environment variables to add the following environment variables in My Computer->-> Advanced-> environment variable-> System variable (assuming your j2sdk is installed in c:\j2sdk1.5.0):
JAVA_HOME=c:\j2sdk1.5.0
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因为它代表当前路径)
path=%JAVA_HOME%\bin
You can then write a simple Java program to test whether the J2SDK has been installed successfully:
public class Test{
public static void main(String args[]){
System.out.println("This is a test program.");
}
}
Save the above program as a file with a file name of Test.java.
Then open the Command Prompt window, the CD to your Test.java directory, and then type the following command
javac Test.java
java Test
At this point, if you see the print this are a test program, the installation is successful, if you do not print out this sentence, you need to carefully check your configuration.
2. After installing Tomcat, add the following environment variables in My Computer->-> Advanced-> environment variable-> System variable (assuming your Tomcat is installed in C:\tomcat):
Catalina_home=c:\tomcat
Catalina_base=c:\tomcat
Then modify the classpath in the environment variable, the Tomat installation directory under the Common\lib (can be added according to the actual) Servlet.jar appended to the CLASSPATH, after the modified classpath are as follows:
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%
CATALINA_HOME%\common\lib\servlet.jar;
Then you can start Tomcat, access http://localhost:8080 in IE, and if you see the Tomcat Welcome page, the installation is successful.
Step three: Build your own JSP app directory
1. To the WebApps directory of Tomcat's installation directory, you can see Root,examples, Tomcat-docs, such as Tomcat's own directory;
2. Create a new directory under the WebApps directory, named MyApp;
3.myapp Create a new directory Web-inf, note that the directory name is case-sensitive;
4.web-inf a new file Web.xml, which reads as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>My Web Application</display-name>
<description>
A application for test.
</description>
</web-app>
5. Under MyApp, create a new JSP page for the test, the file name is index.jsp, and the contents are as follows:
<html>
<body>
<center>
Now time is: <%=new java.util.Date()%>
</center>
</body>
</html>
6. Restart Tomcat
7. Open the browser, enter http://localhost:8080/myapp/index.jsp to see the current time, the description is successful.