我从这里运行了spring-boot-sample-web-static项目,对pom进行了改动
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并添加此类以从同一static
文件夹位置提供重复页面index2.html :
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class Rester {
@RequestMapping(value = "/rand", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
private RandomObj jsonEndpoint() {
return new RandomObj();
}
@RequestMapping(value = "/tw")
public String somePg() {
return "index2";
}
}
Run Code Online (Sandbox Code Playgroud)
json url工作正常,但是当我尝试访问localhost时:8080/tw我得到一个空白页面,并且在控制台中出现此错误:
2017-02-22 15:37:22.076 ERROR 21494 --- [nio-8080-exec-9] o.s.boot.web.support.ErrorPageFilter : Cannot forward to error page for request [/tw] as the response has already been committed. As a result, the response …
Run Code Online (Sandbox Code Playgroud) spring-boot ×1