Step one: Download jdk and tomcat: JDK download and Tomcat download
The latest jdk is 1.6.10 and tomcat is 6.0. It is recommended that jdk 1.4 or above and tomcat 4.0 or above
Step 2: Install and configure your jdk and tomcat: execute the installation program of jdk and tomcat, and then set the installation path according to the path.
1. After installing jdk, you need to configure the environment variables. Add the following environment variables in My Computer-gt; Properties-gt; Advanced-gt; Environment Variables-gt; System Variables (assuming your jdk is installed in C:\Program Files\Java):
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_10
classpath=.;JAVA_HOME\lib\dt. jar; JAVA_HOME\lib\tools.jar; (.; must not be less, because it represents the current path)
path=JAVA_HOME\bin Then you can write a simple java program to test whether the JDK 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 named Test.java.
Then open the command prompt window, cd to the directory where your Test.java is located, and then type the following command
javac Test.java
java Test
If you see This is a test program. printed out at this time, it means the installation is successful. If this sentence is not printed out, you need to carefully check your configuration. 2. After installing Tomcat, add the following environment variables in My Computer-gt; Properties-gt; Advanced-gt; Environment Variables-gt; System Variables (assuming your tomcat is installed in c:\tomcat):
CATALINA_HOME: c:\tomcat
CATALINA_BASE: c:\tomcat
TOMCAT_HOME: C:\Tomcat
Then modify the classpath in the environment variable, Append servlet.jar under common\lib in the tomat installation directory to the classpath. The modified classpath is as follows:
classpath=.; JAVA_HOME\lib\dt.jar; JAVA_HOME\lib\tools .jar;?TALINA_HOME\common\lib\servlet-api.jar;
Note that the latest version of Tomcat may not have the common folder. Therefore, the path of servlet-api.jar should be
TALINA_HOME\lib\servlet-api.jar; please modify it according to your own situation!
Then you can start tomcat and access it in IE. If you see the tomcat welcome page, the installation is successful.
Step 3: Create your own jsp app directory
1. Go to the webapps directory of the Tomcat installation directory, you can see ROOT, examples, tomcat-docs and other things that Tomcat comes with directory;
2. Create a new directory under the webapps directory and name it myapp;
3. Create a new directory WEB-INF under myapp. Note that the directory name is size sensitive. Written;
4. Create a new file web.xml under WEB-INF with the following content:
5. Create a new test jsp page under myapp with the file name index. jsp, the content of the file is as follows:
6. Restart Tomcat
7. Open the browser, enter the current time and see that it is successful.
Step 4: Create your own Servlet:
Write your first Servlet:
In your new Application myapp/WEB-INF/ Create a new HelloWorld.java in the classes/test directory
Then use javac HelloWorld.java to compile this file. If it fails to import javax.servl
et.*
Then you should copy the servlet-api.jar file in C:\Tomcat\common\lib to C:\JDK\jre\lib\ext, compile it again, and there will be no problem!
Then press the following file structure in C:\Tomcat\webapps\myapp in the Tomcat directory:
myapp\index.jsp
myapp\WEB -INF\classes\test\HelloWorld.class (Put the HelloWorld.class file generated above here and enter it in the browser, so the Server reports the expected error: Error 404--Not Found Servlet must use C:\Tomcat\ Register the web.xml file under the directory webapps\myapp\WEB-INF.
Open the web.xml file with EditPlus.
In lt; web-appgt; lt; /web-appgt;Add the following program:
lt;servletgt;
lt;servlet-namegt;HelloWorldlt;/servlet-namegt;
lt ;servlet-classgt;test.HelloWorldlt;/servlet-classgt;
lt;/servletgt;
lt;servlet-mappinggt;
lt;servlet- namegt;HelloWorldlt;/servlet-namegt;
lt;url-patterngt;/HelloWorldlt;/url-patterngt;
lt;/servlet-mappinggt;
Why? lt;servletgt;
lt;servlet-namegt;HelloWorldlt;/servlet-namegt;
lt;servlet-classgt;test.HelloWorldlt;/servlet-classgt; //Class path
lt;/servletgt;
Indicates the specified included servlet class. lt;servlet-mappinggt;
lt;servlet-namegt; HelloWorldlt;/servlet-namegt;
lt;url-patterngt;/HelloWorldlt;/url-patterngt;
lt;/servlet-mappinggt;
means Specify which URL pattern HelloServlet should be mapped to.
After modifying web.xml, restart the Server, and then enter, then a big Hello, World! is waiting for you
Congratulations!
Step 5: Create your own java Bean
1. Create a new TestBean.java in your new Application myapp/WEB-INF/classes/test directory
and then use it as usual javac TestBean.java to compile this file.
2. Then create a new jsp file in your new application directory myapp: testBean.jsp
Okay, determine the location of each file:
myapp\index.jsp
myapp\testBean.jsp
myapp\WEB-INF\web.xml
myapp\WEB-INF\classes\ test\HelloWorld.class
myapp\WEB-INF\classes\test\TestBean.class
3. Restart Tomcat. If necessary, enter in the browser: If you are lucky, you will see it To:
Java Bean Test: The