0

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?

enter image description here

Mansur Nashaev
  • 293
  • 1
  • 5
  • 15

1 Answers1

0

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>
Community
  • 1
  • 1
sidgate
  • 14,650
  • 11
  • 68
  • 119
  • match the folder structure. move hello.jsp to WEB-INF/jsp folder – sidgate Sep 19 '16 at 23:14
  • I added properties, dependencies and moved my jsp file to WEB-INF/jsp folder, but it's still not working. – Mansur Nashaev Sep 20 '16 at 09:56
  • 1
    For me the basic project works just fine. Please take a look at https://github.com/sidgate/webexample and you can then compare – sidgate Sep 20 '16 at 18:37
  • thank you very much. This is a great example, it helped me a lot. How did you create this project, what documentation you referred to? I would like to learn Spring MVC, but can't even create a project. – Mansur Nashaev Sep 20 '16 at 22:36
  • And another question: when I run your project using Spring Boot configuration in Intellij IDEA, it starts and after a few seconds displays. But when I downloaded the project via Spring Initializr, it does not turn off. there is no problem when i run your project with tomcat , I just want to understand the difference – Mansur Nashaev Sep 20 '16 at 22:39
  • I use STS (spring tool suite) for generating the project, haven't worked with Intellij, so cannot help much. But make sure you include `web` dependency in starter project, otherwise it will just be a standalone app – sidgate Sep 20 '16 at 23:34
  • I'm sorry, but could you, please, describe how you create a project in STS? I downloaded STS and created a project, but my problem is not resolved. – Mansur Nashaev Sep 21 '16 at 09:35
  • @MansurNashaev you have to create spring starter project. Add `web` as dependency when you create a project. Please accept the answer if it solves your purpose – sidgate Sep 27 '16 at 21:32