看报错信息是找不到 javax.servlet 包 。这个是tomcat 内的jar包。但是我build path 查看是加了tomcat 的。。
最后在pom.xml 添加依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope> <!--- provided 是编译时使用,但并不放入lib中
</dependency>
可以编译通过。。想起建项目时使用的是maven-archetype-quickstart。 我使用maven-archetype-webapp 方式建立一个项目,把代码复制进去,不添加上面的那个 dependency ,可以编译通过。。
说明是因为建立项目使用了quickstart 没有默认带入tomcat.