2. Create a new Spring Starter Project
3. Check the Web Options and enter a group(org.demo), artefact(exampleweb), and package name(org.demo.exampleweb).
4. Add the following dependences to pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.54</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Note: you may add the dependencies with the use of the Dependeces tab such as
For tomcat-embed-jasper:
For jstl
5. Add ViewResolver properties to application.properties in the src/main/resources directory
##View Resolver Configuration
spring.view.prefix=/WEB-INF/jsp
spring.view.suffix=.jsp
6. Create the following directories in your projects
7. Add a new jsp page named home.jsp. Use the following code for the JSP page
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
This is an example
8.Create a new class named RootController in the package org.demo.exampleweb.controllers
9. Add the following code
package org.demo.exampleweb.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class RootController {
@RequestMapping("/")
public String showHomePage(){
return "home";
}
}
10. Run your App with Spring Boot App
11. Open a browser and enter localhost:8080 as URL
No hay comentarios:
Publicar un comentario