【问题标题】:SpringBoot Web Application : JSP page throws 404 errorSpring Boot Web 应用程序:JSP 页面抛出 404 错误
【发布时间】:2017-09-18 08:29:25
【问题描述】:
There was an unexpected error (type=Not Found, status=404).

点击http://localhost:8080时在我的浏览器中呈现上述错误

MySpringBoot 起始页:

@SpringBootApplication 
public class AppStart  { 
    public static void main(String[] args) {
        SpringApplication.run (AppStart.class,args);
    }
}

我的控制器:

@Controller
public class MyController {
@RequestMapping("/hello/{name}")
public  @ResponseBody ModelAndView hello ( @PathVariable String name){  
    System.out.println("AppStartController:hello ");
    ModelMap model = new ModelMap();
    model.addAttribute("name", name);
    return new ModelAndView("index");   
   }
}

我的 index.jsp 有“Hello World”文本。

【问题讨论】:

    标签: java maven jsp tomcat spring-boot


    【解决方案1】:

    通过在位于 src/main/resources/application.properties 中添加以下属性可以解决此问题,并且索引页面会按预期显示。

    spring.mvc.view.prefix:/
    spring.mvc.view.suffix:.jsp
    

    【讨论】:

      猜你喜欢
      • 2017-10-06
      • 2021-12-18
      • 1970-01-01
      • 2020-03-08
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      相关资源
      最近更新 更多