Struts 2 <s: head> exemple

La balise <s: head> est utilisée pour générer les informations d’en-tête HTML telles que le codage, les fichiers CSS ou JavaScript. Voir l’extrait suivant:

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<s:head/>
</head>
<body>
..

Assume you are using the default xhtml theme, it will render the output according to the “ template\xhtml\head.ftl ” file

<html>
<tête>
<link rel = "stylesheet" href = "/votre__projet/struts/xhtml/styles.css" type = "text/css"/>
<script src = "/votre__projet/struts/utils.js" type = "text/javascript"> </script>
</head>
<body>
..

Pour inclure votre nouveau fichier js ou css, ajoutez-le simplement dans le fichier de modèle “ template \ xhtml \ head.ftl ” et exportez-le via la balise <s: head> .

En fait, cette balise <s: head> n’est pas requise pour être placée en haut et se déformer par la balise HTML <head>, par exemple

<head>
<s:head/>
</head>

Vous pouvez le mettre n’importe où, il suffit de sortir le chemin du fichier CSS et js (défaut dans le thème xhtml)

<head>
</head>
<body>
<s:head/>
...

To improve the website performance, the good practice is always put CSS file on top of the page; while the js file on bottom of the page. So, the <s:head> tag may not suitable, a good practice should be create new tag to output the CSS and js file separately, e.g <s:css> and <s:javascript> .