0

application.yml

spring:
    mvc.view:
        prefix: /
        suffix: .jsp

SampleController.java

package springboot_demo;

import javax.annotation.Resource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import springboot_demo.service.StudentService;

@Controller
@SpringBootApplication
public class SampleController extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SampleController.class);
    }

    @Resource
    private StudentService studentService;


    @RequestMapping("/")
    public String home(Model model) {
        model.addAttribute("data", studentService.list());
        return "index";
    }

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

The 'data' is correctly fetched from database, but the JSP page seems not compiled. I visit http://localhost:8080 and the browser shows me like this:

<%@page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<h2>Hello World!</h2>
<c:forEach items="${data }" var="i">
<h2>${i.id }${i.name }</h2>
</c:forEach>
</body>
</html>
kryger
  • 12,906
  • 8
  • 44
  • 65
ldeng
  • 23
  • 4
  • How does your pom.xml/gradle file look? – heldt Apr 15 '16 at 12:31
  • Possible duplicate of [JSP file not rendering in Spring Boot web application](http://stackoverflow.com/questions/20602010/jsp-file-not-rendering-in-spring-boot-web-application) – kryger Apr 15 '16 at 13:33
  • Where is your jsp files located? As per your configuration it should be under `src/main/webapp`. Also share your pom.xml. – Sanjay Rawat Apr 15 '16 at 20:56

0 Answers0