@[2900498871@qq.com]
直接切入正题,首先是否可以访问controller 方法(如图)
启动类代码片
.
// An highlighted block
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
@Controller
@SpringBootApplication
public class DemoApplication {
@RequestMapping("/name")
public String name(Map<String, Object> map) {
map.put("name", "Clark");
System.out.println("============================================这是一个测试");
return "index";
}
@RequestMapping("/index")
@ResponseBody
public String index(Map<String, Object> map) {
map.put("name", "Clark");
return "index";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
报错
.
============================================这是一个测试
2019-04-13 10:19:25.054 WARN 12100 --- [nio-8080-exec-5] o.s.w.s.r.ResourceHttpRequestHandler : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/index.jsp]
浏览器报错:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Apr 13 10:19:25 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
说明controller 可以正常运行 jsp解析出现问题。
这里我pom.xml 导包需要导入依赖
<!-- tomcat 依赖包 -->
<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>
<!--<scope>provided</scope>-->
</dependency>
<!-- servlet 依赖包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<!-- JSTL (JSP standard Tag Library) JSP 标准标签库 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
到这里一般jsp就可以运行了,但是要确定这个依赖被maven 载入(按住ctrl+鼠标右键 看是否可以进入),反正我被这个问题坑了好久。。。最好maven 重新导入一下(org.apache.tomcat.embed)比较重要,没有导入就是404…剩下的就是解析问题了