Utilisation des APIs EL et JSTL
Accès rapide :
La vidéo Les codes de la vidéo La vue viewArticle La classe Summary.java (le contrôleur du MVC utilisé pour la page summary) La vue summary
La vidéo
Cette vidéo présente deux APIs de la plate-forme Java EE : l'EL (l'Expresion Language) et la JSTL (la Java Standard Tag Library).
Ces deux librairies sont très utiles pour la génération de pages Web dynamiques, liées aux données.
Utilisation des APIs EL et JSTL
Les codes de la vidéo
La vue viewArticle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<%@ page language= "java" contentType= "text/html; charset=UTF-8" pageEncoding= "UTF-8" % >
<%@ taglib uri= "http://java.sun.com/jsp/jstl/core" prefix= "c" % >
<!DOCTYPE html >
<html >
<head >
<meta charset= "UTF-8" >
<title > View article </title >
<link rel= "stylesheet" type= "text/css" href= "styles.css" / >
</head >
<body >
<h1 > View article - ${connectedUser.login} </h1 >
<br/ >
Identifier: ${catalogBrowser.currentArticle.idArticle} <br/ >
Brand: ${catalogBrowser.currentArticle.brand} <br/ >
Description: ${catalogBrowser.currentArticle.description} <br/ >
Unitary price: ${catalogBrowser.currentArticle.unitaryPrice} <br/ >
<br/ >
<form action= "viewArticle" method= "post" >
<input name= "btnPrevious" type= "submit" value= "Previous" / >
<input name= "btnAdd" type= "submit" value= "Add to shopping cart" / >
<input name= "btnNext" type= "submit" value= "Next" / >
</form > <br/ >
${catalogBrowser.shoppingCartSize} article <c:if test= "${catalogBrowser.shoppingCartSize gt 1}" > s </c:if >
in the shopping cart. <br/ >
<a href= "summary" > View the shopping cart </a >
</body >
</html >
La vue viewArticle
La classe Summary.java (le contrôleur du MVC utilisé pour la page summary)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package fr.koor.webstore.ihm;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet ( urlPatterns="/summary" )
public class Summary extends HttpServlet {
private static final long serialVersionUID = -1204635336479052777L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession( true );
if ( session.getAttribute( "connectedUser" ) == null ) {
response.sendRedirect( "login" );
return ;
}
request.getRequestDispatcher( "/summary.jsp" ).forward( request, response );
}
}
La classe Summary.java
La vue summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<%@ page language= "java" contentType= "text/html; charset=UTF-8" pageEncoding= "UTF-8" % >
<%@ taglib uri= "http://java.sun.com/jsp/jstl/core" prefix= "c" % >
<!DOCTYPE html >
<html >
<head >
<meta charset= "UTF-8" >
<title > Shopping cart summary </title >
<link rel= "stylesheet" type= "text/css" href= "styles.css" / >
</head >
<body >
<h1 > Shopping cart summary - ${connectedUser.login} </h1 >
<br/ >
<table style= "width: 60%; border: 1px solid black; margin: auto;" >
<thead >
<tr >
<th > Identifier </th >
<th > Description </th >
<th > Brand </th >
<th > Unitary price </th >
<th > Quantity </th >
</tr >
</thead >
<tbody >
<c:forEach items= "#{catalogBrowser.shoppingCart}" var= "line" >
<tr >
<td > ${line.article.idArticle} </td >
<td > ${line.article.description} </td >
<td > ${line.article.brand} </td >
<td > ${line.article.unitaryPrice} </td >
<td > ${line.quantity} </td >
</tr >
</c:forEach >
</tbody >
</table >
<br/ > <br/ >
<a href= "viewArticle" > Return to catalog </a >
</body >
</html >
La vue summary
2024 © SARL Infini Software - Tous droits réservés
Mentions légales
Les informations présentes dans ce site vous sont fournies dans le but de vous aider à acquérir les compétences nécessaires à
l'utilisation des langages ou des technologies considérés. Infini Software ne pourra nullement être tenu responsable de l'utilisation
des informations présentes dans ce site.
De plus, si vous remarquez des erreurs ou des oublis dans ce document, n'hésitez surtout pas à nous le signaler en envoyant un mail
à l'adresse : .
Les autres marques et les noms de produits cités dans ces documents sont la propriété de leurs éditeurs respectifs.
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :