Use JSP in spring boot

Home / Use JSP in spring boot

How to use JSP in spring boot

In this post, we ‘ll see how to use JSP pages in spring boot project, For using JSP in spring boot we have to follow the given below steps :

1  Add the below dependency in your pom.xml file

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

or you can copy the above dependency for the Maven Repository

Download Dependency

2   Create a folder name JSP inside your WEB-INF folder

src/main/webapp/WEB-INF/jsp

3  Add the following lines to your application.properties file to use JSP

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

4  Now make a JSP file with any name inside your JSP folder, Let’s say we create a file with name index.jsp

src/main/webapp/WEB-INF/jsp/index.jsp

5  Now make a controller for URL endpoint

@RequestMapping("/")
public String getFirstJspPage() {
System.out.println("inside first controller");
return "index";           // here index is the name of jsp file
}

Now just run your spring boot main class and go to your browser and type localhost:8080 you will see the content of your JSP file there.

 

you also may like

How to Upload files in spring boot projects .

How to create spring boot project

Help Others, Please Share

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *

x