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

115,454

Solution 1

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.

Solution 2

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>

Solution 3

import javax.servlet

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

Solution 4

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.

Solution 5

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

Share:
115,454
Admin
Author by

Admin

Updated on November 06, 2020

Comments

  • Admin
    Admin over 3 years

    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?

  • Bloodboiler
    Bloodboiler about 10 years
    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.
  • Nav
    Nav over 9 years
    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?!!
  • DaddyMoe
    DaddyMoe about 9 years
    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
  • rkrishnan
    rkrishnan over 8 years
    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.
  • Ajay Sharma
    Ajay Sharma over 8 years
    Thanks a ton, but could you please elaborate what exactly problem was?
  • Richard Rebeco
    Richard Rebeco about 8 years
    It works for me, I had to go to the EAR properties. thank you so much!!
  • Tobi123
    Tobi123 almost 8 years
    Same Problem, but this dind't work. Tomcat 8 was already selected and uncheck/apllay/check/apply dind't help. Any ideas?
  • 猫IT
    猫IT almost 5 years
    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.
  • Mutaealim
    Mutaealim over 3 years
    It worked for me...thank you sooo mucchhhh dude!!!!!!!!!!!1