Free tutorials for Java, Eclipse and Web programming



Servlet and JSP development with Eclipse WTP - Tutorial

Lars Vogel

Version 1.0

02.11.2009

Revision History
Revision 0.1 - 0.212.12.2007Lars Vogel / Waldemar Geppart
First Version
Revision 0.310.09.2008Lars Vogel
Moved Webservice part to own article
Revision 0.413.10.2008Lars Vogel
Added JSP and MVC example, added authorization chapter
Revision 0.512.04.2009Lars Vogel
Rework, removed DB example
Revision 0.618.05.2009Lars Vogel
Improved wording, general clean-up
Revision 0.702.07.2009Lars Vogel
Update to Eclipse 3.5
Revision 0.803.07.2009Lars Vogel
Moved Servlet which creates JavaScript to http://www.vogella.de/blog/?p=395
Revision 0.918.07.2009Lars Vogel
Minor improvements
Revision 1.002.11.2009Lars Vogel
Closing the file counter

Eclipse Web Tool Platform (WTP)

This article describes the development of servlets and JSPs with Eclipse WTP.

It starts by developing servlets which keeps track of the number of visitors of a website, including a servlet which stores this data into a file.

The creation of JavaServerPages and well as the creation of a war file to run the application in a web container is also explained.

This article assume that you have already basic Eclipse knowledge. The following uses the JDK 1.6, Eclipse 3.5 (Galileo) and Tomcat 6.0 for its examples.


Table of Contents

1. Eclipse Web Tool Platform
1.1. Overview of Eclipse WTP
1.2. Additional Eclipse WTP resources
1.3. Dynamic Web Project
2. Tomcat Installation
3. Installation of WTP
4. WTP Configuration
4.1. Server
5. Servlets
5.1. Overview
5.2. Project
5.3. Creating Data Access Object
5.4. Creating the Servlet
5.5. Run
6. JavaServer Pages (JSPs)
6.1. Overview
6.2. Create Project
6.3. Create the Controller (servlet)
6.4. Create the Views (JSP)
6.5. Run it
7. Web Archive - How to create a war file from Eclipse
8. Thank you
9. Questions and Discussion
10. Links and Literature
10.1. Source Code
10.2. Web development resources
10.3. Other Resources

1. Eclipse Web Tool Platform

1.1. Overview of Eclipse WTP

Tip

In case you are new to Java web development you may want to get a quick overview of webdevelopment with Java in the following short article: Introduction to Java Webdevelopment .

Eclipse WTP provides tools for developing standard Java web applications and Java EE applications. Eclipse WTP simplifies the creation of web artifacts and provides a runtime environment in which these artifacts can be deployed, started and debugged. Typical web artifacts in a Java environment are HTML pages, XML files, webservices, servlets and JSPs.

The following article will focus on the creation of servlets and JSP with Eclipse WTP and how to use the runtime environment of Eclipse to test them.

Eclipse WTP supports all mayor webcontainer, e.g. Jetty and Apache Tomcat as well as the mayor Java EE application server. This tutorial will be based on Apache Tomcat.

1.2. Additional Eclipse WTP resources

The development of webservices with Eclipse WTP is covered in Webservices with Axis2 and the Eclipse Web Tool Platform (WTP) - Tutorial .

The development of JavaServerFaces is covered in JavaServer Faces (JSF) development with Eclipse WTP JSF - Tutorial and JSF with Apache Myfaces Trinidad and Eclipse .

1.3. Dynamic Web Project

Eclipse uses builders which are responsible for working with the relevant artifacts. Eclipse WTP uses "Dynamic Web Projects". These projects provide the necessary builders to run, debug and deploy a Java web application. Therefore for the development of Java web application you create "Dynamic Web Projects" .