java - Spring Boot Web 应用程序 : JSP page throws 404 error

标签 java maven jsp tomcat spring-boot

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 :

@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”文本。

最佳答案

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

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

关于java - Spring Boot Web 应用程序 : JSP page throws 404 error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43540972/

相关文章:

java - Maven 依赖项位置 - Java 和 Eclipse

java - 一次从数据库中获取所有问题还是一次获取一个问题?

java - BindingResult 和 bean 名称 'configId' 的普通目标对象都不能用作请求属性 Jasper 异常

java - Swagger ReaderListener 未调用

java - Java 错误,但没有显示错误位置,我该怎么办?

maven - 如何在 Kotlin 代码上强制执行完整的文档

javascript - 来自 Java 程序的 ChartJS 折线图或条形图

java - 与连接表的一对多关系

java - Spigot Minecraft 插件编码 NoClassDefFound 错误 mysql

maven - Gradle - 生成没有依赖的pom