ChatGPT解决这个技术问题 Extra ChatGPT

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

This question already has answers here: How do I import the javax.servlet / jakarta.servlet API in my Eclipse project? (16 answers) Closed 2 years ago.

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

javax.servlet.ServletException cannot be resolved to a type

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

are you using Eclipse?

K
Kishan_KP

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


Thanks. In Eclipse Kepler you may need to toggle the check box off, apply, toggle it back on and apply again for this to take effect.
Unbelievable! This actually solved it! I'd classify this as a bug. It's extremely silly for an IDE to complain about such a problem for such a small reason which it should have taken care of by itself. What am I using an IDE for, for god's sake?!!
Using Eclipse Mars, and still this is an issue ;-). I had Tomcat 6 and 7 selected under Targeted runtimes and I had to make sure "only" Tomcat 7 is selected (that's my runtime) to get rid of this error.
Thanks a ton, but could you please elaborate what exactly problem was?
Thanks. It worked for me. I don't know why other persons got the error but in my case I was messing around the server. I deleted it and made it from scratch again. I had 12 errors in the beginning. Cleaning removed half of it but 6 remained even after a reboot (actually a boot from yesterday to today). Now this has solved my issue. NB: Even before applying this my code was working if I ran the server.
A
Arjan Tijms

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:

<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>

This environment agnostic answer worked for me, I was on Intellij IDE converting my spring boot app to work with my existing dedicated tomcat server when i got the above ServletException error. Thanks bunch
C
Community

https://i.stack.imgur.com/4QFXL.png

STEP 1

Go to properties of your project ( with Alt+Enter or righ-click )

STEP 2

check on Apache Tomcat v7.0 under Targeted Runtime and it works.

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


V
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"

if it is maven pom.xml issue, try added this to the 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.


i
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.


A
Arash moradabadi

As almost anyone said, adding a runtime service will solve the problem. But if there is no runtime services or there is something like Google App Engine which is not your favorite any how, click New button right down the Targeted Runtimes list and add a new runtime server environment. Then check it and click OK and let the compiler to compile your project again. Hope it helps ;)


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now