Install Eclipse Helios for Java EE Developers
File -> New -> Dynamic Web Project
Wizard:
1. Enter project name UE1
New Wizard:
1. click on New Runtime and choose Apache Tomcat v6.0, NEXT
2. click Download and Install... and install tomcat, FINISH
2. FINISH
Right click on your project UE1 within the project explorer and choose New -> HTML file
Wizard:
1. edit file name index.html, FINISH
replace the content of index.html with the following code and save
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Meine WebApp-Startseite</title>
</head>
<body>
<h3> Meine WebApp-Startseite </h3>
<p> <a href="MyServlet">/MyServlet</a> </p>
</body>
</html>
right click on your project UE1 within the project explorer and choose New -> Servlet
Wizard:
1. enter package name de.fub.servletpackage
2. enter class name MyServlet, FINISH
replace the content of MyServlet.java with the following code and save
package de.fub.servletpackage;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
static final long serialVersionUID = 1L;
@Override
public void doGet( HttpServletRequest requ, HttpServletResponse resp )
throws ServletException, IOException
{
resp.setContentType( "text/html" );
PrintWriter out = resp.getWriter();
out.println( "<html>" );
out.println( "<h3> Hallo, mein erstes Servlet meldet sich </h3>" );
out.println( "<a href='/UE1'>zurück</a>" );
out.println( "</html>" );
out.close();
}
}
right click on your project UE1 within the project explorer and choose Run As -> Run On Server
Wizard:
1. Choose Tomcat v6.0 Server
2. Check Always use this server when running this project, FINISH
Start your web browser and check http://localhost:8080/UE1/