1

Here is the code in question:

post("user/login ", (request, response) -> {
            return "hello";
});

And here is the error that happens right after the return statement:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeaders(Ljava/lang/String;)Ljava/util/Collection;
    at spark.utils.GzipUtils.checkAndWrap(GzipUtils.java:64)
    at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:251)
    at spark.webserver.JettyHandler.doHandle(JettyHandler.java:61)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
    at org.eclipse.jetty.server.Server.handle(Server.java:517)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:302)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Thread.java:745)

From what I've read, there is some version problem in my jars - here are the jars I'm using:

jar versions

I am using maven, and followed the directions found in Spark's documentation. How can I get past this error?

3
  • 1
    I have just couple ideas on top of my head. Do you run your app server which supports servet api 3.1? Do you have just one servlet-api on classpath? Commented Mar 16, 2016 at 20:56
  • I printed out the classpath: ...../lib/javax.servlet-api-3.1.0.jar ...../idea-IU-143.1821.5%20(2)/lib/servlet-api.jar Commented Mar 17, 2016 at 2:44
  • @chalimartines you were right! I added an answer to my question. Thank you, that's amazing. Commented Mar 17, 2016 at 2:58

2 Answers 2

4

Found it! I printed out everything on the classpath. Here are a few of the entries:

...../lib/javax.servlet-api-3.1.0.jar 
...../idea-IU-143.1821.5%20(2)/lib/servlet-api.jar

Turns out Intellij was loading something I didn't know about (maybe I caused it to do that, not sure) that conflicted with the jar I needed. I went into that directory and renamed the Intellij jar. It's apparently causing some problem in Intellij (it reported some internal IDE error) but my code works now.

I wonder why Intellij's jars would ever have anything to do with my project... yikes.

Sign up to request clarification or add additional context in comments.

1 Comment

What is your project SDK? It could be you have set intellij to be the SDK. That can cause problems.
0

I went to File> Project Structure> Libraries and then deleted javax.servlet-api 2.5 (kept 3.1.0).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.