Class web.ServletDemo1 is not a Servlet
The error message displayed on the web when an error is reported:
The error message displayed on the console is as follows:
The original file of the Servlet in pom.xml is as follows:
<!-- 导入servelt的坐标-->
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
The way to correct the error: just add the scope of scope
<!-- 导入servelt的坐标-->
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Knowledge point: make a summary of scope:
- The type of value of the scope tag:
- compile: default value, can be omitted. This value indicates that the dependency needs to participate in the compilation, testing, and running cycles of the project, and it should also be included when packaging.
- test: This dependency only participates in test-related work, including compilation and execution of test code, and will not be packaged.
- runtime: The dependent project does not need to participate in the compilation of the project, but its participation is required for later testing and running cycles. Compared with compile, the compilation is skipped.
- provided: This dependency does not need to be included when packaging, other facilities will provide it. In fact, the dependency can theoretically participate in the compilation, testing, running and other cycles. It is equivalent to compile, but the exclude operation is done in the packaging phase.
- system: In terms of participation, it is the same as provided, but the dependent items will not be downloaded from the maven repository, but taken from the local file system. The property of systemPath needs to be added to define the path
Dependency scope |
compile |
test |
run |
example |
Complie |
Y |
Y |
Y |
Logback |
test |
Y |
Junit |
||
provided |
Y |
Y |
Servlet-api |
|
runtime |
Y |
Y |
Jbdc driver |
|
system |
Y |
Y |
Store local jar packages |
|
import |
Introducing Dependency Management |