title: Simple Servlet with Eclipse Juno and J2EE Preview server
body: <p>I'm trying to create my first HelloWorld servlet with Eclipse Juno and view it in the J2EE Preview Server.</p>
  
  <p>This is my Servlet class:</p>
  
  <pre><code>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;
  
  /**
   * Servlet implementation class HelloWorld
   */
  public class HelloWorld extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public HelloWorld() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/html");
          PrintWriter pw = response.getWriter();
          pw.println("&lt;html&gt;");
          pw.println("&lt;head&gt;&lt;title&gt;Hello World&lt;/title&gt;&lt;/title&gt;");
          pw.println("&lt;body&gt;");
          pw.println("&lt;h1&gt;Hello World&lt;/h1&gt;");
          pw.println("&lt;/body&gt;&lt;/html&gt;");
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
  }
  </code></pre>
  
  <p>And this is my web.xml automatically generated by eclipse:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;HelloWorld&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;display-name&gt;HelloWorld&lt;/display-name&gt;
      &lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;
      &lt;servlet-class&gt;HelloWorld&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/HelloWorld&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>When I select "Run on Server" > "J2EE Preview" I get this:</p>
  
  <blockquote>
    <p>Error 404 - Not Found</p>
    
    <p>No context on this server matched or handled this request. Contexts
    known to this server are:</p>
    
    <p>HelloWorld(/HelloWorld)</p>
  </blockquote>
  
  <p>Where am I doing wrong?</p>