原来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的配置如下

spring mvc项目原来用myeclipse启动改为idea启动,启动成功后访问网站报404

相关文章:

  • 2021-11-18
  • 2021-12-09
  • 2022-01-07
  • 2021-07-19
  • 2021-10-07
  • 2021-11-30
  • 2021-12-29
猜你喜欢
  • 2021-05-02
  • 2022-01-19
  • 2021-10-31
  • 2021-06-18
  • 2021-12-12
相关资源
相似解决方案