javax.servlet.jsp.PageContext 无法解析为类型

发布于 2024-12-23 06:06:50 字数 3055 浏览 2 评论 0原文

我在我的 jsp 页面中看到以下错误 -

javax.servlet.jsp.PageContext cannot be resolved to a type
javax.servlet.jsp.JspException cannot be resolved to a type

我看过有关此问题的帖子并尝试了一些建议的操作。 BalusC 提供了很好的输入 - JSTL1.2 和 Standard.jar 不得一起使用。我这样做了,它解决了这个问题一段时间 - 但它又重新出现了。我不确定是否还有其他罐子碰撞。我已将所有 jar 定义为 Maven 中的依赖项。以下是我指定的 pom.xml 的依赖项 -

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.38</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>2.2.2</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>

</dependencies>

I am seeing the below errors in my jsp page -

javax.servlet.jsp.PageContext cannot be resolved to a type
javax.servlet.jsp.JspException cannot be resolved to a type

I have seen a post on this and tried few things that were suggested. BalusC provided a great input - JSTL1.2 and Standard.jar must not be used together. I did this and it fixed the issue for sometime - but it is reappearing. I am not sure if I have any more jar collisions. I have defined all the jars as dependencies in Maven. The below are the dependencies that I have specified pom.xml -

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.38</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>2.2.2</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>

</dependencies>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

唯憾梦倾城 2024-12-30 06:06:50

您需要在项目中导入 JSP API,这些 API 不包含在 servlet-api 中

。在我的项目中,解决方案是:

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

You will need to import in your project the JSP APIs, which are not included in servlet-api

In my project, the solution is:

<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.1</version>
  <scope>provided</scope>
</dependency>
你与昨日 2024-12-30 06:06:50

这个答案中给出了对我有用的解决方案。转到项目属性>目标运行时间>选择运行时的复选框(在我的例子中是 Apache Tomcat 7)。
就这样。现在就构建项目,一切都会好起来的。

The solution that worked for me, is given in this answer. Go to project properties > Targeted runtimes > Select the checkbox for a runtime (Apache Tomcat 7 in my case).
That's all. Just build the project now and everything will be fine.

土豪我们做朋友吧 2024-12-30 06:06:50

假设这是 Web 应用程序的 pom...

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

其中许多依赖项应设置为 provided,因为它们是由容器提供的。您不应将它们与您的应用程序捆绑在一起。请参阅 Maven 依赖范围。如果不这样做可能会导致未定义的行为。

到底提供哪些依赖项取决于容器。

Assuming this is the pom for a web application...

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

A number of these dependencies should be set as provided as they are provisioned by the container. You should not bundle these with your application. See Maven dependency scopes. Failure to do this may result in undefined behaviour.

Exactly which dependencies are provided depends on the container.

感性不性感 2024-12-30 06:06:50

“这个答案给出了对我有用的解决方案。转到项目属性 > 目标运行时 > 选择运行时的复选框(在我的例子中是 Apache Tomcat 7)。
就这样。现在就构建项目,一切都会好起来的。”

这个解决方案对我有用。

"The solution that worked for me, is given in this answer. Go to project properties > Targeted runtimes > Select the checkbox for a runtime (Apache Tomcat 7 in my case).
That's all. Just build the project now and everything will be fine."

This solution worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文