My primary environment settings:
Eclipse installation path is e:/java/eclipse
Tomcat path is the default installation path: C:/Program Files/apache Software foundation/ Tomcat 5.0
Environment variable: catalina_home value is C:/Program files/apache Software Foundation/tomcat 5.0
to establish Tomcat project name Testtomcat ; Create a servlet class.
1, create the test package and the HelloWorld class, and write the following code
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 helloworld extends httpservlet .... {
protected void doget (httpservletrequest arg0, HTTPSERVLETRESPONSE ARG1)
throws servletexception, ioexception {
// TODO automatically generate method stubs
printwriter out=arg1.getwriter ();
out.print ("Hello world!!!!!!!!!!!!");
}
}
2, the deployment of documents, testtomcat/web-inf in the establishment of web.xml fill in the following content
<?xml version= "1.0" encoding= "Shift_JIS"?>
<! 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>
<!--to establish a mapping between the servlet name and the class name of the servlet-->
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>test. Helloworld</servlet-class>
</servlet>
<!--Specifies the name of the Servlet class for a specific URL. All URLs starting with/test are treated with a servlet named Test, that is, the HelloWorld class-->
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/test/*</url-pattern>
</servlet-mapping>
<!--set the Tomcat session timeout limit-->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!--set default home-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3, in the project to create a index.jsp file, input simple content such as: This page is index.jsp
4, publish the project
(1), if you only want to test in eclipse.
5.0/conf/catalina/localhost was established under the C:/Program Files/apache Software foundation/tomcat testtomcat.xml. Enter the following content.
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<context docbase= "E:/java/eclipse/workspace/testtomcat" path= "/testtomcat" reloadable= "true" workDir= "E:Java/" Eclipse/workspace/testtomcat/work ">
</Context>
(2), if you want to permanently publish. The Testtomcat project C:/Program files/apache Software foundation/tomcat 5.0/webapps can be.
4, input web site test Servlethttp://localhost:8090/testtomcat/test/helloworld. The port defaults to 8080 because I'm occupied, so I changed it to 8090 when I installed Tomcat. Enter http://localhost:8090/TestTomcat/test index.jsp