title: Embedded Jetty forward servlet response to JSP
body: <p>Using Embedded Jetty I am trying to get a very simple servlet to forward to JSP page once the servlet doGet() has executed. However instead of reaching the JSP it simply recursively forwards to the same doGet() which is calling the forward.  </p>
  
  <p>Im very new to this stuff but its like it either cant find the JSP and instead maps to the only servlet that it can find or else I'm not registering the JSP or something.  please help.</p>
  
  <p>My code is as follows...</p>
  
  <pre><code>import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlet.ServletHolder;
  
  public class RunHelloServlet {
  
  public static void main(String[] args) throws Exception {
      Server server = new Server(8080);
  
      ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
      contextHandler.setContextPath("/");
      server.setHandler(contextHandler);
  
      contextHandler.addServlet(new ServletHolder(new HelloServlet()), "/*");
      server.start();
      server.join();
  }
  
  public static class HelloServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      public HelloServlet() {
      }
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
          String par1 = request.getParameter("par1");
          request.setAttribute("key", par1);
          try {
              request.getRequestDispatcher("/result.jsp").forward(request, response);
          }
          catch (ServletException e1) {
              e1.printStackTrace();
          }
  
      }
  }
  }
  </code></pre>
  
  <p>My JSP located at .\src\main\webapp\WEB-INF\result.jsp  </p>
  
  <pre><code>&lt;%@ page language="javascript" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My pom.xml...  </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;com.hp.it.kmcs.search&lt;/groupId&gt;
    &lt;artifactId&gt;JettyTest&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
  
    &lt;name&gt;JettyTest&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
   &lt;properties&gt;
      &lt;jettyVersion&gt;7.2.0.v20101020&lt;/jettyVersion&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.jetty.aggregate&lt;/groupId&gt;
          &lt;artifactId&gt;jetty-all-server&lt;/artifactId&gt;
          &lt;version&gt;7.6.0.RC1&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;!-- This plugin is needed for the servlet example --&gt;
          &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
          &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;${jettyVersion}&lt;/version&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;&lt;goals&gt;&lt;goal&gt;java&lt;/goal&gt;&lt;/goals&gt;&lt;/execution&gt;
          &lt;/executions&gt;
          &lt;configuration&gt;
            &lt;mainClass&gt;com.hp.it.kmcs.JettyTest.RunHelloServlet&lt;/mainClass&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>