1

我在 Eclipse 中,前一段时间我正在使用这种方法:http://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setContentLengthLong(long)现在我无法管理这行得通。我正在使用 JDK 1.7,并且在中插入了以下依赖项pom.xml

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>

我已经用 Maven 清理并更新了项目。我什至关闭并打开了 Eclipse。当我写:

response.setContentLengthLong(downloadFile.length());

我得到:

The method setContentLengthLong(long) is undefined for the type HttpServletResponse

我究竟做错了什么?

4

3 回答 3

0

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.

于 2014-10-05T12:37:56.610 回答
0

我今天遇到了同样的问题。我正在使用 IDEA,所以我从 maven 选项卡中打开“显示依赖项”,然后搜索“servlet-api”,有一个版本为 2.4。

从 pom.xml 中排除它,构建成功。

于 2017-03-29T01:02:59.613 回答
-1
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

反而

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
</dependency>

使用..然后......解决......

于 2018-10-27T16:39:00.020 回答