Cannot forward to error page for request [/] as the response has already been committed. As a result

我遇到这个错误是因为我创建的spring boot 项目,使用jsp模板,但是jsp页面放在了resources文件夹里面所以出现了这个错误


创建了传统web项目的结构之后,修复了该问题,就是将jsp页面放在webapp/WEB-INF/ 文件夹下面


程序入口class文件

package com.xiaogang;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@Controller
public class App extends SpringBootServletInitializer{

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("hello");
        System.out.println("App.index");
        return mv;
    }

    @RequestMapping(value = "/error", method = RequestMethod.GET)
    public String error() {
        System.out.println("App.error");
        return "hello";
    }

    public static void main(String[] args )
    {
        System.out.println( "Hello World!" );
        new SpringApplicationBuilder().web(true).sources(App.class);
    }
}


maven文件配置

xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0

    com.xiaogang
    boot-tomcat
    1.0-SNAPSHOT
    war

    boot-tomcat
    http://maven.apache.org

    
        UTF-8
    

    
        org.springframework.boot
        spring-boot-starter-parent
        1.4.1.RELEASE
    

    

        
            junit
            junit
            test
        

        
        
            org.springframework.boot
            spring-boot-starter-web
            
                
                    org.springframework.boot
                    spring-boot-starter-tomcat
                
            
        

        
        
            org.apache.tomcat.embed
            tomcat-embed-jasper
            provided
        
        
            javax.servlet
            jstl
            1.2
            jar
        
        
            javax.servlet
            servlet-api
            3.0-alpha-1
            provided
        
    

    
        report
    




你可能感兴趣的:(Cannot forward to error page for request [/] as the response has already been committed. As a result)