Spring Boot With JSP and Spring MVC | Java Inspires

#JavaInspires

Spring Boot With JSP and Spring MVC




Project Folder Structure:



welcome.jsp
<html>
<head>
<title>Spring Boot JSP</title>
</head>
<body>
 <h1>${message}</h1>
</body>
</html>

application.properties
# Spring MVC related
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

WelcomeController.java
package com.javainspires.jspdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(path = "/demo")
public class WelcomeController {

 @RequestMapping(method = RequestMethod.GET, path = "/welcome")
 public ModelAndView welcome(Model model) {

  model.addAttribute("message", "Welcome to Java Inspires");

  return new ModelAndView("welcome");
 }
}

SpringBootJspAppApplication.java
package com.javainspires.jspdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootJspAppApplication {

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




Start the spring boot from the main class. And go to browser and hit the following URL:

http://localhost:8080/demo/welcome






Post a Comment

Previous Post Next Post