Commit a32fb303 by Patryk Czarnik

Obsługa JSP

parent 73a26765
......@@ -46,6 +46,28 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Dodatkowe zależności, aby używać JSP w Springu -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- numer wersji będzie automatycznie nadany przez Spring Boot -->
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
</dependency>
<!-- https://jakarta.ee/specifications/tags/3.0/jakarta-tags-spec-3.0.html -->
<!-- Dla Spring Boot 2.x to była właściwa zależność dla JSTL:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
-->
</dependencies>
<build>
......
package sklep.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
......@@ -15,10 +16,10 @@ public class RootController {
}
@GetMapping("/time")
@ResponseBody
public String currentTime() {
public String currentTime(Model model) {
LocalDateTime now = LocalDateTime.now();
return now.toString();
model.addAttribute("dt", now);
return "show_time.jsp";
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>Show time</title>
</head>
<body>
<h1>Bieżący czas</h1>
<p>Bieżący czas: ${dt}</p>
<h3>Wybrane pola:</h3>
<ul>
<li>rok: <strong>${dt.year}</strong></li>
<li>dzień roku: <strong>${dt.dayOfYear}</strong></li>
<li>sekunda: <strong>${dt.second}</strong></li>
</ul>
<p>za dwa tygodnie będzie: ${dt.toLocalDate().plusWeeks(2)}</p>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment