Tomcat 6.0 Configuration
First step : Download JDK and Tomcat.
The latest JDK for 1.6.04,tomcat is 6.0, recommended jdk1.4 above, tomcat4.0 above
Step two : Install and configure your JDK and Tomcat: Perform JDK and tomcat setup, and then set up the path to install.
1. After installing the JDK, you need to configure the environment variables to add the following environment variables in My Computer-> properties-> Advanced-> environment variable-> system variable (assuming your JDK is installed in c:jdk1.4.2):
java_home=c:jdk1.4.2
Classpath=.; %java_home%libdt.jar;%java_home%libtools.jar; (.;;; Must not be less because it represents the current path)
Path=%java_home%bin
You can then 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 are 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-> properties-> Advanced-> environment variable-> system variable (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, add the Servlet.jar under the Tomat installation directory to classpath, and modify Classpath as follows:
Classpath=.; %java_home%libdt.jar;%java_home%libtools.jar; Talina_home%commonlibservlet-api.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 the directory of Tomcat, such as Root,examples,?tomcat-docs;
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:?
<body>
<center>
Now: <%=new java.util.Date ()%>
</center>
</body>
6. Restart Tomcat
7. Open the browser, enter http://localhost:8080/myapp/index.jsp to see the current time, the description is successful.
Step Fourth : Build Your own servlet:
Write to your first servlet:
Create a new Helloworld.java in your new application Myapp/web-inf/classes/test directory
Package test;
Import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doget (httpservletrequest request,httpservletresponse response) th
Rows Servletexception,ioexception
{
Response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter ();
Out.println ("
Out.println ("This is the My A-Servlet");
Out.println ("</title>
Out.println ("
Out.println ("</body>
}
}
Then use Javac Helloworld.java to compile this file, if there is no import JAVAX.SERVL
et.*
Then it should be c:tomcatcommonlib inside the Servlet-api.jar file copy to the C:jdkjrelibext, compile again, there is no problem!
Then, in the C:tomcatwebappsmyapp inside the Tomcat directory, press the following file structure:
myappindex.jsp
Myappweb-infclassestesthelloworld.class (Put the Helloworld.class file that was generated above this
Inside
Then in the browser input http://localhost:8080/myapp/HelloWorld, so the server is expected to complain: error 404--not Found
What's going on?
The servlet must be registered using the Web.xml file below the C:tomcatwebappsmyappweb-inf directory,
Open this Web.xml file with EditPlus,
Add the following procedure in <web-app></web-app>:
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>test. Helloworld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>