Reputation: 1232
I am in Eclipse and some time ago I was using this method: http://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setContentLengthLong(long) Now I can't manage to mek it work. I am using JDK 1.7 and I have inserted the following dependency in pom.xml
:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
I have cleaned and updated the project with Maven. I have even closed and opened Eclipse. When I write:
response.setContentLengthLong(downloadFile.length());
I get:
The method setContentLengthLong(long) is undefined for the type HttpServletResponse
What am I doing wrong?
Upvotes: 1
Views: 5252
Reputation: 1
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
instead
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
use.. then ... solved.....
Upvotes: -2
Reputation: 839
I met the same problem today. I am using IDEA, so I open the "Show Dependencies" from the maven tab, and search for the "servlet-api", there is one with version 2.4.
Exclude it from pom.xml, and build succeeded.
Upvotes: 0
Reputation: 997
The most probably cause would be the second comment on your post. "Some other version of the servlet api is also in your classpath. Open the HttpServletResponse class in Eclipse, and look in the explorer which jar file it's part of. – JB Nizet"
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html
If you look at the docs for jdk 6 you will find that it does not contain that method.
Upvotes: 0