1. install Tomcat 6.0.2
2. install Eclipse 3.4.2
3. install TomcatPlugin for Eclipse
http://www.eclipse.org/ => click "View All Plugins"
input "Tomcat" and click "SEARCH"
click "Sysdeo Tomcat Launcher Plugin " from the search result.
...
download "tomcatPluginV321.zip" into local disk, and extract it
copy file folder "com.sysdeo.eclipse.tomcat_3.2.1" to eclipse installed plugin directory:
C:/Program Files/eclipse-SDK-3.4.2-win32/eclipse/plugins/
4. restart eclipse
"C:/Program Files/eclipse-SDK-3.4.2-win32/eclipse/eclipse.exe " -clean
You can find three tomcat icon at toolbar (start, stop, restart Tomcat)
5. Create Servlet project
5.1 create a directory at Tomcat webapps directory
C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/TomcatServlet
5.2 create Tomcat project from eclipse
Eclipse FIle => New => Others => Java => Tomcat Project
Project Name: TomcatServlet
Use user defined location: C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/TomcatServlet
next, next, leave others as default value.
5.3 create servlet class
new class with name "MyServlet" and superclass "MyServlet". whether it has a package name or not, it's depend on you.
rewrite the doGet(...) function as follow:
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException
{
response.setContentType("text/html");
PrintWriter writer;
writer = response.getWriter();
writer.println("Hello World!");
}
6. configure tomcat servlet
create an configure file web.xml at:C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/TomcatServlet/WEB-INF
its content is some like:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat MyServlet</display-name>
<description>
Welcome to Tomcat MyServlet
</description>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>package.name.MyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
<!-- this section can be redefined as
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
then all http://host:port/TomcatServlet/XXX or not will come here.
-->
</web-app>
7. restart Tomcat
8. Verfy from a brower
http://localhost:8080/TomcatServlet/MyServlet
-- appendix
Only one source java file located under Tomcat 6.0/webapps/TomcatServlet/WEB-INF/src/com....
and corresponding there is only one .class file located under Tomcat 6.0/webapps/TomcatServlet/WEB-INF/classes/com...