简体   繁体   中英

Spring App won't work with JSP

I am new to Spring Framework. Trying to make a Java based Spring MVC project. Here is my main application class

@SpringBootApplication
@ComponentScan
public class DemoApplication {

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

}

@Controller
public class HelloController {

    @RequestMapping("/")
    public String hello(){
        return "hello";
    }

}

When I run the project I get the error

There was an unexpected error (type=Not Found, status=404).
No message available

Why Spring can not display JSP files?

在此处输入图片说明

Add following to application.properties

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

Edit :You can refer sample project here

Below step is not required, but worth a try.


As per another post , you need following dependencies

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM