idea : springboot访问jsp页面,后台未报错,前台报404
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Oct 16 09:51:12 CST 2019
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/views/index.jsp
TestController .java
@Controller
public class TestController {
private static final Logger Log = LoggerFactory.getLogger(TestController.class);
@RequestMapping("index")
public String index(){
Log.info("Index page .........");
return "index";
}
}
MyApplication.java(springboot 启动类)
package com.jqcode;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(MyApplication.class, args);
}
}
pom.xml
<!-- WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 使用Jasper引擎解析JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- scope 为provided打包时排除 IDEA中应注释掉 -->
<!--<scope>provided</scope>-->
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
application.properties
server.port=8080
#设置Tomcat编码
server.tomcat.uri-encoding=UTF-8
#设置视图解析器路径
spring.mvc.view.prefix=/WEB-INF/views/
#设置视图解析器后缀
spring.mvc.view.suffix=.jsp
application.yml
server:
port: 8080
tomcat:
uri-encoding: UTF-8
spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
仔细检查过该依赖的jar包都已依赖 视图解析的相关配置都已配置 但就是访问不到 /WEB-INF/views/index.jsp页面
查阅了很多资料,idea默认路径是工程的路径 而不是模块的路径。所以我们要手动选择模块路径。