title: Issues while using Jetty Embedded to handle JSP. (JasperException: Unable to compile class for JSP)
body: <p>I am trying to set up Jetty Embedded to handle JSPs.</p>
  
  <p>The HelloServlet works properly when I type <em>localhost:8080</em>. I get the list of the files in the jsp folder when I type <em>localhost:8080/jsp</em>, but if I take an index.jsp into the folder I will get an exception. The JSP contains only a short HTML text and this line in the body: <code>&lt;%= new java.util.Date() %&gt;</code>.</p>
  
  <p>What could be the problem?</p>
  
  <p>This is the exception:</p>
  
  <pre><code>2013-07-08 16:29:10.007:WARN:oejs.ServletHandler:qtp1957204991-11: 
  org.apache.jasper.JasperException: Unable to compile class for JSP
      at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:661)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
      at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
      at org.eclipse.jetty.server.Server.handle(Server.java:445)
      at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
      at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
      at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
      at java.lang.Thread.run(Unknown Source)
  Caused by: 
  java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
      at java.security.AccessControlContext.checkPermission(Unknown Source)
      at java.security.AccessController.checkPermission(Unknown Source)
      at org.eclipse.jetty.server.handler.ContextHandler$Context.getClassLoader(ContextHandler.java:2161)
      at org.apache.jasper.compiler.TagPluginManager.init(TagPluginManager.java:83)
      at org.apache.jasper.compiler.TagPluginManager.apply(TagPluginManager.java:57)
      at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:240)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
      at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
      at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
      at org.eclipse.jetty.server.Server.handle(Server.java:445)
      at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
      at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
      at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>This is my app:</p>
  
  <pre><code>package main;
  import org.eclipse.jetty.server.Handler;
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.server.ServerConnector;
  import org.eclipse.jetty.server.handler.ContextHandler;
  import org.eclipse.jetty.server.handler.HandlerList;
  import org.eclipse.jetty.server.handler.ResourceHandler;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlet.ServletHolder;
  import org.eclipse.jetty.webapp.WebAppContext;
  
  public class SimplestServer
  {
      public static void main(String[] args) throws Exception
      {
          Server server = new Server();
          ServerConnector connector = new ServerConnector(server);
          connector.setHost("127.0.0.1");
          connector.setPort(8080);
          server.addConnector(connector);
  
          WebAppContext webAppContext = new WebAppContext();
          webAppContext.setContextPath("/jsp");
          webAppContext.setResourceBase("./jsp/");
          webAppContext.setInitParameter("dirAllowed", "false");   
  
          ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
          servletContextHandler.setContextPath("/");
          servletContextHandler.addServlet(new ServletHolder(new HelloServlet()), "/*");
  
          HandlerList handlers = new HandlerList();
          handlers.setHandlers(new Handler[] { webAppContext, servletContextHandler });
  
          server.setHandler(handlers);    
          server.start();
          server.join();
      }
  }
  </code></pre>
  
  <p>JSP code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "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;%= new java.util.Date() %&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I solved the previous problem <a href="https://stackoverflow.com/questions/7892325/getclassloader-from-servletcontext-leads-to-accesscontrolexception">this way</a>. Now I am in trouble again.
  I didn't changed anything, just added a new row to the policy file and I get a new exception, when I try to load the jsp page. ( <code>org.apache.jasper.JasperException: java.lang.IllegalStateException: No org.apache.tomcat.InstanceManager set in ServletContext</code> )
  I found a few articles about this, and it may happens because I added a tomcat library manually to my project. ( <em>tomcat-juli.jar</em> ). However if I delete this library from the project, I get an other exception (just after running the application, not when I want to load a JSP.) ( <code>java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory</code> ). So that's because I added tomcat-juli.jar.</p>
  
  <p>This is the full trace of the IllegalStateException exception:</p>
  
  <pre><code>org.apache.jasper.JasperException: java.lang.IllegalStateException: No org.apache.tomcat.InstanceManager set in ServletContext
  at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:582)
  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
  at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:261)
  at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101)
  at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:546)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
  at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
  at org.eclipse.jetty.server.Server.handle(Server.java:445)
  at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
  at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
  at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
  at java.lang.Thread.run(Unknown Source)
  Caused by: 
  java.lang.IllegalStateException: No org.apache.tomcat.InstanceManager set in ServletContext
      at org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(InstanceManagerFactory.java:35)
      at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:171)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:582)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
      at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:261)
      at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101)
      at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:546)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
      at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
      at org.eclipse.jetty.server.Server.handle(Server.java:445)
      at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)
      at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224)
      at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p><strong>UPDATE 2:</strong>
  I've added tomcat-juli.jar to the "Apache Tomcat v7.0" libraries. So this time I don't bundle the jar into my app, but I still get the IllegalStateException exception. In addition I don't understand why the app want to use tomcat libraries while I am using Jetty.</p>