i 'm new in spring boot and i wanted to start with a simple example however nothing seemed to work this my controller:
Package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class testController {
RequestMapping("view/aboutus")
public String greeting(Model model) {
model.addAttribute("name", "azertyyyy");
return "aboutus"; }}
and this is the jsp view:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE>
<html> <body> ${name}
<p>hello world</p> </body></html>
i added the needed dependencies:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
and i added the prefix and suffix in application.properties
when i run the application only hello world is shown on the view without the name variable, after searching here i changed the view directory from src/main/webapp/view to src/main/resource/templates but spring boot couldn't find the view anymore
I am not sure if you are fully aware of the changes we have to make when we want to run the application as war package.
Directory Structure for the project
Following is the code changes I have to done to run the JSP
pom.xml
Main Class
Rest Controller - which redirects to JSP
application.properties - define the path for JSPs