12

I have a web service project implemented in java and it also contains jsp pages. I deploy it on jetty 8.1.5 on my machine and it works normally. But when I deploy on a windows server 2003 with jetty 8.1.3 it gives this exception:

org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.runtime.ELContextImpl

This is the full trace:

java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.runtime.ELContextImpl
    at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1002)
    at org.apache.jsp.home.index_jsp._jspService(org.apache.jsp.home.index_jsp:52)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:542)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:271)
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:98)
    at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:557)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:499)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
    at org.eclipse.jetty.server.Server.handle(Server.java:350)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
    at java.lang.Thread.run(Unknown Source)

Any idea what is this exception and how to fix it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sami
  • 7,797
  • 18
  • 45
  • 69
  • It doesn't really seem to apply, so am not offering this up as an "answer". However, that error message generally occurs (to me!) when I have a copy of servlet-api-2.4 in the classpath ahead of 2.5 or 3.0. Can you check that on the server that is failing? – JoeG Sep 19 '12 at 13:08

7 Answers7

11

That can happen if your webapp ships with servletcontainer-specific JAR files such as jasper.jar, jetty.jar servlet.jar, etc in the /WEB-INF/lib for some unclear reason. This is in turn conflicting with with a different versioned JAR file on the target servletcontainer.

Remove that servletcontainer-specific JAR file from your webapp's /WEB-INF/lib. It doesn't belong there. It's supposed to be already supplied by the servletcontainer itself.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have checked /WEB-INF/lib and could not find any jasper.jar file. Could you please explain what do you mean with a servletcontainer-specific jasper.jar? – Sami Sep 13 '12 at 08:57
  • I found jetty-specific jars in the same folder and they are version 8.1.5 specific such as: `jetty-continuation-8.1.5.v20120716.jar`, `jetty-http-8.1.5.v20120716.jar` ... I tried removing these but then I got HTTP 503 service not available and exceptions when I start jetty. Is it an issue if I deploy on jetty 8.1.3 with these 8.1.5 jars shipped in the war file. – Sami Sep 13 '12 at 09:55
  • I added a new [question](http://stackoverflow.com/questions/12407105/jars-shipped-in-war-conflicting-with-jetty) and added list of all jars there. – Sami Sep 13 '12 at 14:04
5

IF you are using maven (I asked on a comment without response), you can avoid conflictive jars using a "provided" scope. When you deploy it for production, jars are not included.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

I'm not sure about jetty's jars but it's probably the same.

IF you are NOT using maven, you should move your conflictive jars (servlets and jetty) to your develompent container lib folder and remove them from your applications WEB-INF/lib folder.

jpaoletti
  • 855
  • 1
  • 13
  • 21
4

If the folder /WEB-INF/lib of your webapp does not contain a jasper.jar (see BalusC' answer), please check whether another webapp is running in your container. Then check if that webapp contains a jasper.jar in its folder /WEB-INF/lib. This happened to us. Be removing jasper.jar from those webapps (sic!), the problem could be solved. Obviously, the webapps are not that isolated for meach other as they should be. The problem appeared as we switched from Tomcat6 to Tomcat7 and jasper.jar (version 6) was bundled accidently with one of our webapps.

rwitzel
  • 1,694
  • 17
  • 21
  • Yes, it was existing in one other web app and removing it fixed the issue. But I still don't understand why this was happening as I posted a [question](http://dev.eclipse.org/mhonarc/lists/jetty-users/msg02555.html) on jetty forums and they said each app executes its own class loader. – Sami Sep 30 '13 at 11:20
3

Apart from the answers mentioned watch out for one more thing. I've another war deployed under the same Tomcat 7.0.42 instance which had a jsp-2.1-6.0.2.jar under its WEB-INF/lib. This jar has org.apache.jasper.runtime.ELContextImpl class.

My understanding was that each webapp has its own classloader and the class files loaded by one webapp is not visible to the other webapp. Still as nothing was working I removed the other war which had that jsp.jar and restarted my tomcat and to my surprise the exception was no longer coming. Somehow this class was getting loaded and causing the issue.

The interesting thing is that both of these wars work perfectly fine in Tomcat 6.x.

saurabh
  • 271
  • 2
  • 3
0

I faced the same problem and tried all suggestions, none worked for me. I finally found out that the issue was caused after using Spring Boot overriding my tomcat version, as I had

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.0.M2</version>

Removing the Spring Boot solves the problem. This answer could provide the solution for using Spring Boot + Maven + Tomcat 8.

Community
  • 1
  • 1
Saeed
  • 1
  • 2
0

For me (Jetty 8.1.14), this exact error message was actually caused by another webapp in the same Jetty container. Are you running more than one webapps?

Mr Auni
  • 708
  • 6
  • 10
  • 1
    If I remember correctly (it's been two years or so now), the problem was caused because of conflicting jars from another web app deployed in the same Jetty container. I ended up splitting them and they both worked fine. – Sami Mar 02 '15 at 14:42
0

Add this line in <context>:

<Loader delegate="true" />

This problem is related with a conflicted jars in the applications tag. This looks like:

<?xml version='1.0' encoding='utf-8'?>
<!-- The contents of this file will be loaded for each web application -->
<Context>

  <!-- Default set of monitored resources -->
  <WatchedResource>WEB-INF/web.xml</WatchedResource>
  <Loader delegate="true" /> <!--this line-->
  <!-- Uncomment this to disable session persistence across Tomcat restarts -->
  <!--
      <Manager pathname="" />
    -->

  <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) -->
  <!--
      <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->

</Context>
maanijou
  • 1,067
  • 1
  • 14
  • 23
leandro lion
  • 51
  • 1
  • 3