logging start......
* install jdk-1_5_0_01-windows-i586-p.exe>>>http://java.sun.com/j2se/1.5.0/download.jsp
* config Java environment variables :
JAVA_HOME=D:\j2sdk1.4.2
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
path=%JAVA_HOME%\bin
////////////////we can test java compiler system by programming a Test.java before continuing//////////////////
* install tomcat 5.0 .28>>>http://www.apache.org/dist/tomcat/tomcat-5/v5.0.28/bin/
/////leave all default but set port to : 80
* config server enviroment:
CATALINA_HOME=D:\Apache Software Foundation\Tomcat 5.0;
CATALINA_BASE=D:\Apache Software Foundation\Tomcat 5.0; classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet-api.jar
/////////////test your server like : in IE address:http://localhost:80; then tomcat wellcome page show s
* copy webapps' directory structture to webapps/myAppDir\:
e.g: mkdir -p D:\Apache Software Foundation\Tomcat 5.0\webapps\myAppDir\WEB-INF
* new file : "webapps\myAppDir\web.xml"
<?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>
* test jsp: "webapps\myAppDir\index.jsp"
<html>
<body>
<center>
Now time is: <%=new java.util.Date()%>
</center>
</body>
</html>
* in IE navigate to URL : http://localhost/myAppDir/index.jsp
////////////////see : Now time is:Tue Apr 04 22:13:51 CST 2006 /////////////////
* write your servlet: Test.java:
/* Created: 04-04-06 22:02:25 by Jin/Jun */
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
out.println("<html><body><h1>This is a servlet test.</h1></body></html>");
out.flush();
}
}
* modify webapps\myAppDir\web.xml for your servlet: caution!!!
<?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>
<servlet>
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<description>A test Servlet</description>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet-mapping> <!--servlet-mapping则是将声明的servlet“映射”到地址/Test上-->
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
</web-app>
* compile your servlet and copy the total directory "test" including "test/Test.java;test\Test.class" to %CATALINA_HOME%\webapps\myAppDir\WEB-INF\classescaution!!!
------------------------------------------------------------caution:修改了web.xml以及新加了class,都要重启Tomcat !!!
log stop.
reference:http://blog.csdn.net/ecaol/archive/2004/06/24/25085.aspx( sth error corrected)