Error java: cannot access javax.servlet.ServletException Class file for javax.servlet.ServletException not found

 I encountered the problem of "Error java: cannot access javax.servlet.ServletException cannot find javax.servle" in the process of learning spring MVC, as shown in the following figure:

Here I use IDEA to develop, deploy it to the local Tomcat, and then I get such an error when compiling, and I checked many solutions on the Internet and it doesn't work. Later, I found a solution and record it here to prevent myself from forgetting it later.


1. Add maven support to the project

Click the project -> right click, select "Add Framework Support" -> select "maven" -> click "OK"

So far, the maven framework has been imported for the project. The reason for importing the maven framework is to use pom.xml to facilitate the import and management of jar packages.


2. Next, configure the following dependencies under the pom.xml file

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
</dependency>
Then run it again and find that it can run successfully

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324714493&siteId=291194637