Commit 59cf756f by Patryk Czarnik

Pierwsze przykłady z JSTL

parent b0dc1df3
...@@ -20,6 +20,26 @@ ...@@ -20,6 +20,26 @@
<version>6.0.0</version> <version>6.0.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- stara klasyczna wersja - tylko dla starszych serwerów. Java EE 8 lub starsze: -->
<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
-->
</dependencies> </dependencies>
<build> <build>
......
...@@ -18,6 +18,10 @@ public class PrzykladowyBean { ...@@ -18,6 +18,10 @@ public class PrzykladowyBean {
this.napis = napis; this.napis = napis;
} }
public String[] getWords() {
return napis.split(" ");
}
public int wylosuj() { public int wylosuj() {
return random.nextInt(1000); return random.nextInt(1000);
} }
......
<%@page import="java.time.LocalTime"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="jakarta.tags.core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
...@@ -38,6 +38,30 @@ ...@@ -38,6 +38,30 @@
--%> --%>
<%-- Biblioteka tagów ("taglib") to jest zestaw poleceń zapisywanych w formie znaczników w obrębie JSP.
Te znaczniki zawsze są poprzedzane prefiksem, np. <c:if>....
Tagliby można definiować samodzielnie, ale w 98% przypadków używa się zestawu nazywanego JSTL
"Java Standard Tag Library"
--%>
<h3>Taglibs</h3>
<ul>
<c:forEach var="i" items="5,10,15">
<li>${i}
<c:choose>
<c:when test="${i % 2 == 0}">parzyste</c:when>
<c:otherwise>nieparzyste</c:otherwise>
</c:choose>
</li>
</c:forEach>
</ul>
<p>Słowa napisu:</p>
<ul>
<c:forEach var="word" items="${obiekt.words}">
<li>${word}</li>
</c:forEach>
</ul>
</body> </body>
</html> </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