I've made an application using `Spring Boot http://localhost:8080/vehicleApp, the contents of my JSP file are getting printed rather than the expected output.
Below is the code:
VehicleApplication.java (main class)
package com.Vehicle.prototype;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class VehicleApplication {
public static void main(String[] args) {
SpringApplication.run(VehicleApplication.class, args);
System.out.println("Vehicle Application started");
}
}
MvcConfig.java
package com.vehicle.prototype.config;
@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
VehicleController.java
package com.vehicle.prototype.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class VehicleController {
@RequestMapping(value="vehicleApp")
public String home(Model model) {
model.addAttribute("greetings", "hello");
return "vehicleApp";
}
}
src/main/webapp/WEB-INF/jsp/vehicleApp.jsp (These same contents are getting printed as it is)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Page</title>
</head>
<body>
<h1>${greetings}</h1>
</body>
</html>
Please let me know what am I missing?
Thank You