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 7014539
In Process

The Archive Base Latest Questions

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

Im try to get my embedded jetty servlet to do some processing and then

  • 0

Im try to get my embedded jetty servlet to do some processing and then pass control over to a JSP which will generate a result page.

The servlet gets mapped and called correctly however it fails to find the JSP. Since Im using embedded jetty I don’t have a web.xml nor do I have a war. Maybe this means jetty doesn’t know where to look for my JSP or something. If this is the case how can I tell eclipse/jetty where to find this or is there something Im missing with how I am calling the forward.

N.B. Im using a regular maven project so had to create the WEB-INF folder myself. Might be a clue to what’s wrong!?

import java.io.IOException;

import javax.servlet.RequestDispatcher;
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;
import org.springframework.core.io.ClassPathResource;

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()), "/hello");

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

        // logic

        try {
            RequestDispatcher r = request.getRequestDispatcher("/result.jsp");
            request.getRequestDispatcher("/WEB-INF/result.jsp").forward(request, response);
        }
        catch (ServletException e1) {
            e1.printStackTrace();
        }

    }
}

}

My pom is as follows…

<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>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.0.RELEASE</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>

  • 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:32:04+00:00Added an answer on May 27, 2026 at 10:32 pm

    So I got this to work using setWar and the correct jars. Using this code it is possible to both address the jsp directly (localhost:8080/result.jsp)and more importantly forward to the jsp using servlets (localhost:8080/hello) .forward command. This will enable me to serve up some dynamic content with my jsp.

    Code as follows… (NB: Embedded Jetty => no web.xml is required)

    import java.io.File;
    import java.io.IOException;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.eclipse.jetty.server.Handler;
    import org.eclipse.jetty.server.Server;
    import org.eclipse.jetty.server.handler.DefaultHandler;
    import org.eclipse.jetty.server.handler.HandlerList;
    import org.eclipse.jetty.servlet.ServletHolder;
    import org.eclipse.jetty.webapp.WebAppContext;
    
    public class RunHelloServlet {
    
    public static void main(String[] args) throws Exception {
    
        System.setProperty("DEBUG", "true");
        Server server = new Server(8080);
    
        WebAppContext webappcontext = new WebAppContext();
        webappcontext.setContextPath("/");
    
        File warPath = new File("C:/dev/workspace/JettyTest", "src/main/webapp");
        webappcontext.setWar(warPath.getAbsolutePath());
        HandlerList handlers = new HandlerList();
        webappcontext.addServlet(new ServletHolder(new HelloServlet()), "/hello");
    
        handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });
        server.setHandler(handlers);
        server.start();
    }
    
    public static class HelloServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        public HelloServlet() {
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    
            // logic
    
            try {
                request.getRequestDispatcher("/result.jsp").forward(request, response);
            }
            catch (Throwable e1) {
                e1.printStackTrace();
            }
    
        }
    }
    }
    

    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</groupId>
        <artifactId>jetty-server</artifactId>
        <version>7.6.0.RC1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-util</artifactId>
        <version>7.6.0.RC1</version>
        <type>jar</type>
        <classifier>config</classifier>
        <scope>compile</scope>
    </dependency>
    
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-2.1-glassfish</artifactId>
        <version>2.1.v20100127</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>3.5.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>servlet-api-2.5</artifactId>
        <version>6.1.14</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>7.6.0.RC0</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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Embedded Jetty I am trying to get a very simple servlet to forward
For some reason if I try to get the actual size of mystruct I
I have been playing about with iText to try get a list of embedded
I get the following error when i try to run a console program which
I try get the mp3 flash player to work with my javascript on all
I try to get to a page straight from Bash at http://www.ocwconsortium.org/ . The
I try to get all WPF window controls collections. In other words i try
I try to get the name of executable name of all of my launched
I try to get the last modification date of a file: NSFileManager *fm =
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304

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.