Java Spring Boot - An error happened during template parsing (template: "class path resource [templates/greeting.html]")

Viewed 11

The full error is: There was an unexpected error (type=Internal Server Error, status=500). An error happened during template parsing (template: "class path resource [templates/greeting.html]")

This is my first spring program and I will appreciate your help. The idea is for a program that outputs one of the 6 possible sentences in the details array.

BasicApplication.java

package edu.aubg.basic;

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

@SpringBootApplication
public class BasicApplication {

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

}

GreetingController.java

package edu.aubg.basic;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {

    @GetMapping("greeting")
    public String greeting(Model model) {
     // Set up an array containing the 6 details
        String[] details = {"My name is ", "My birthday is ", "My street address is ",
                "My town is ", "My father's name is ", "My mother's name is "};
     // Generate an integer random number in the range 0 – 5
        int min=0;
        int max=5;
        
        int b = (int)(Math.random()*(max-min+1)+min);  
     // Use this random number to index into the array
        String detail = details[b];
     // and store the selected array element, i.e. detail in the greeting model property. 
     model.addAttribute("greeting", detail);
     return "greeting";
 }
}

greeting.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Greeting</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
    .text {
        font-size: 150%;
    }
    </style>
</head>
<body>
    <p class="text" th:text="${greeting)" />
</body>
</html>

index.html

<!DOCTYPE HTML>
<html>
<head>
    <title>Greetings</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
    .text {
        font-size: 150%;
    }
    </style>
</head>
<body>
    <p class=”text”> Get your greeting <a href="/greeting"> here </a></p>
</body>
</html>
0 Answers
Related