Embedded Jetty Jsp Save

Example of Embedded Jetty with JSP support

Project README

Example: Embedded Jetty w/ JSP Support

This is a maven project, to build it:

$ mvn clean package

To run the example org.eclipse.jetty.demo.Main:

$ mvn exec:java

Open your web browser to:


To stop Jetty:

use CTRL+C

Code Of Interest

See org.eclipse.jetty.demo.Main

Set a Servlet Temp Directory

It is important for JSP to define a temp directory suitable for managing itself. Such a directory will be used for converting the JSP source into a java file and then compiling it into a class. A sub directory in this temp directory will be automatically added by the JSP implementation for loading the compiled JSP classes.


Set a non-System Classloader

The JSP implementation will refuse to the System Classloader (per JSTL + JSP spec), this will wrap the system classloader in a simple URLClassLoader suitable for use by the JSP implementation.

// Set Classloader of Context to be sane (needed for JSTL)
// JSP requires a non-System classloader, this simply wraps the
// embedded System classloader in a way that makes it suitable
// for JSP to use
ClassLoader jspClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader());

Jsp Servlet must be named "jsp"

The JspServlet must be named "jsp" (per JSP spec).

// Add JSP Servlet (must be named "jsp")
ServletHolder holderJsp = new ServletHolder("jsp",JspServlet.class);

Default Servlet must exist

The JSP implementation relies on various Servlet Spec requirements, but mainly the fact that a "default" named servlet must exist.

// Add Default Servlet (must be named "default")
ServletHolder holderDefault = new ServletHolder("default",DefaultServlet.class);
Open Source Agenda is not affiliated with "Embedded Jetty Jsp" Project. README Source: jetty-project/embedded-jetty-jsp
Open Issues
Last Commit
4 weeks ago

Open Source Agenda Badge

Open Source Agenda Rating