Participer au site avec un Tip
Rechercher
 

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 :

Utilisation des APIs EL et JSTL

Création d'une librairie de Tags (TagLib) Servlet d'upload de fichiers



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" />
            &nbsp; &nbsp;
            <input name="btnAdd" type="submit" value="Add to shopping cart" />
            &nbsp; &nbsp;
            <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


Création d'une librairie de Tags (TagLib) Servlet d'upload de fichiers