原来mvc项目在用myeclipse启动,pom里少引用servlet的依赖,pom没有加载静态资源,需要更改pom文件
1.增加servlet的依赖
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>
2.增加使pom能读到静态资源,重新配置tomcat启动即可
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> <resources> <!-- 打包时将jsp文件拷贝到META-INF目录下--> <resource> <!-- 指定resources插件处理哪个目录下的资源文件 --> <directory>src/main/webapp</directory> <!-- <targetPath>/</targetPath> --> <includes> <include>**/**</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/**</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/java</directory> <!-- 资源文件需要排除java文件 --> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> </build>
3.tomcat的配置如下