javax.servlet.ServletException 无法解析为 Spring Web 应用程序中的类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15781902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 05:50:33  来源:igfitidea点击:

javax.servlet.ServletException cannot be resolved to a type in spring web app

springjspservletexception

提问by Kishan_KP

I am developing web app using spring frame work, but i am getting following error in some of the jsp pages.

我正在使用 spring 框架开发 Web 应用程序,但在某些 jsp 页面中出现以下错误。

javax.servlet.ServletException cannot be resolved to a type

I have included servlet-apialso but still same error message is displaying. How to over come this problem?

我也包括在内,servlet-api但仍然显示相同的错误消息。如何克服这个问题?

回答by Kishan_KP

I guess this may work, in Eclipse select your project→ then click on project menu baron top → goto to properties→ click on Targeted Runtimes→ now you must select a check boxnext to the server you are using to run current project → click Apply→ then click OK button. That's it, give a try.

我想这可能有效,在 Eclipse 中选择您的项目→ 然后单击顶部的项目菜单栏→ 转到属性→ 单击目标运行时→ 现在您必须选中用于运行当前项目的服务器旁边的复选框→ 单击应用→ 然后单击确定按钮。就这样,试试。

回答by Tiago

It seems to me that eclipse doesn't recognize the java ee web api (servlets, el, and so on). If you're using maven and don't want to configure eclipse with a specified server runtime, put the dependecy below in your web project pom:

在我看来,eclipse 无法识别 java ee web api(servlet、el 等)。如果您正在使用 maven 并且不想使用指定的服务器运行时配置 eclipse,请将下面的依赖项放在您的 web 项目 pom 中:

<dependency>  
    <groupId>javax</groupId>    
    <artifactId>javaee-web-api</artifactId>    
    <version>7.0</version> <!-- Put here the version of your Java EE app, in my case 7.0 -->
    <scope>provided</scope>
</dependency>

回答by nalinc

import javax.servlet

导入 javax.servlet

STEP 1

第1步

Go to propertiesof your project ( with Alt+Enteror righ-click )

转到项目的属性(使用Alt+Enter或右键单击)

STEP 2

第2步

check on Apache Tomcat v7.0under Targeted Runtimeand it works.

Targeted Runtime下检查Apache Tomcat v7.0,它可以工作。

source: https://stackoverflow.com/a/9287149

来源:https: //stackoverflow.com/a/9287149

回答by Venkata Naresh Babu

Add the server(tomcat) from Right click on the Project and select the "Properties" go to "Project Factes" "Runtime tab" other wise "Target Runtime"

添加服务器(tomcat)从右键单击项目并选择“属性”转到“项目事实”“运行时选项卡”其他明智的“目标运行时”

if it is maven pom.xml issue, try added this to the pom.xml

如果是 maven pom.xml 问题,请尝试将其添加到 pom.xml

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

it will solve the issue.

它将解决问题。

回答by Arash moradabadi

As almost anyone said, adding a runtime service will solve the problem. But ifthere is no runtime services or there is something like Google App Enginewhich is not your favorite any how, click Newbutton right down the Targeted Runtimeslist and add a new runtime server environment. Then check it and click OKand let the compiler to compile your project again.

Hope it helps ;)

正如几乎所有人所说,添加运行时服务将解决问题。但是,如果没有运行时服务或Google App Engine 之类的东西不是您最喜欢的,请单击Targeted Runtimes列表下方的New按钮并添加新的运行时服务器环境。然后检查它并单击确定并让编译器再次编译您的项目。 希望能帮助到你 ;)

回答by ivan.ukr

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

worked for me.

对我来说有效。