Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:00:41+00:00 2026-05-27T22:00:41+00:00

Using Embedded Jetty I am trying to get a very simple servlet to forward

  • 0

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.

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.

My code is as follows…

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();
        }

    }
}
}

My JSP located at .\src\main\webapp\WEB-INF\result.jsp

<%@ page language="javascript" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>

</body>
</html>

My pom.xml…

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.hp.it.kmcs.search</groupId>
  <artifactId>JettyTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>JettyTest</name>
  <url>http://maven.apache.org</url>

 <properties>
    <jettyVersion>7.2.0.v20101020</jettyVersion>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.eclipse.jetty.aggregate</groupId>
        <artifactId>jetty-all-server</artifactId>
        <version>7.6.0.RC1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <!-- This plugin is needed for the servlet example -->
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${jettyVersion}</version>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution><goals><goal>java</goal></goals></execution>
        </executions>
        <configuration>
          <mainClass>com.hp.it.kmcs.JettyTest.RunHelloServlet</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:00:42+00:00Added an answer on May 27, 2026 at 10:00 pm

    It looks like you’ve mapped HelloServlet so that it handles almost every request. When you try to forward the request from HelloServlet to /result.jsp, Jetty matches the path /result.jsp to /* and so forwards the request right back to HelloServlet (which forwards it to /result.jsp and so on recursively).

    You should make your servlet mapping more restrictive (e.g. /hello instead of /*).

    Furthermore, since your .jsp file is in WEB-INF, you should be forwarding to /WEB-INF/result.jsp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an embedded Jetty implementation as my servlet container. Here is a
I'm trying to run a simple jsf-2.0 tutorial using embedded glassfish 3.0 and keep
Im try to get my embedded jetty servlet to do some processing and then
I am using embedded-linux for device which has Arch ARMv5 Speed 266MHZ, vfpu and
My Flex web page is using an embedded .otf font in the main css
I've tried to run a Wicket app in an embedded Jetty, using this code:
I'm using Jetty 7.0 embedded mode and looking for a way to force Jetty
I have a simple Java web application using HSQLDB embedded database. The application is
I'm using embedded Jetty to launch a standard Java webapp. My launcher is something
I'm using Jetty 6 as an embedded web server in my Java app. Heretofore,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.