Jetty 7.6 does not compile JSP files

I am new with Jetty and JSP. I am now trying to create simple server with Embedded Jetty and JSP for the html generating.

What I should have to mention first, that I am restricted with the Jetty version. The version I have to use is Jetty 7.6.x.x.

My need is to create few servlets, where I can dispatch the request/response to the JSP file. The thing is that the JSP file does not seem to be compiled and instead of evaluating expressions, it throws the whole script as a plain text in browser. Let’s have a look.

public void start() throws Exception {
    server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();

    // Base URI to webapp, where jsp files are located
    URI baseUri = getWebRootResourceUri();

    // Create Servlet context
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

    // Default Servlet (always last, always named "default")
    ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class);
    holderDefault.setInitParameter("resourceBase", baseUri.toASCIIString());
    holderDefault.setInitParameter("dirAllowed", "true");
    context.addServlet(holderDefault, "/");



This is the JSP file

    <!DOCTYPE html>
        <title>Coin Flipper</title>
        <h1>Coin Flipper</h1>
        <p>Flipping a coin...</p>
        <% if(Math.random() < .5){ %>
        <% }
        else{ %>
        <% } %>
        <hr />
        <p>Refresh to flip again.</p>

And this is the result:

enter image description here

I am not using web.xml, but I won’t mind using it if it will fix my problem.

Also here is my maven dependencies:

        <!-- Embedded web server -->
        <!-- -->

        <!-- -->

        <!-- -->




In versions of Jetty prior to 7.5.0, the JSP infrastructure made use of the Eclipse Java Compiler (ecj.jar) which is supplied in $JETTY_HOME/lib/jsp. For jetty-7.5.0 we upgraded the version of JSP to jsp-impl-2.1.3.b10 (from Glassfish). In this version, the JSP infrastructure ALWAYS tries to acquire a Java compiler from the JVM if the version of Java is 1.6 or above. Therefore, if you are using a JRE, JSPs are unable to compile so you must use a full JDK. Alternatively, you can precompile your JSPs (which is preferable in a production deployment in any case). The Jetty JSPC Maven Plugin is helpful for precompilation.

This sounds exactly like your issue. Either use a JDK or precompile your JSPs, as instructed by the link above.

Leave a Reply

Your email address will not be published. Required fields are marked *