关于idea请求到webapp的jsp页面出现404的问题

       我们使用idea做web程序的时候,根据maven结构特点需要在main目录下建一个webapp目录,然后在这个webapp目录下建立一个个jsp页面,如下:

然后添加所需要的依赖:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <!--jstl标签依赖的jar包start -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <!--jstl标签依赖的jar包end -->

        <!-- servlet依赖的jar包start -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <!-- servlet依赖的jar包start -->

        <!-- jsp依赖jar包start -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <!-- jsp依赖jar包end -->

最好在<build></build>标签里添加如下<resources></resources>标签:

<resources>
	<resource>
		<directory>src/main/java</directory>
		<includes>
			<include>**/*.xml</include>
		</includes>
	</resource>
	<resource>
		<directory>src/main/resources</directory>
		<includes>
			<include>**/*.*</include>
		</includes>
	</resource>
	<resource>
		<directory>src/main/webapp</directory>
		<targetPath>META-INF/resources</targetPath>
		<includes>
			<include>**/*.*</include>
		</includes>
</resource>

然后正常的在controller中写跳转到jsp页面,却发现如下所示错误:

 这个错误在idea中很常见,主要是有个配置没配好导致的,只要如下配置一下就好了:

 

或者这样也可以:

这里找到你的module的正确路径。然后再启动,访问。就ok了。。。 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页