Пример Struts 2 <s: head>

Тег <s: head> используется для вывода информации заголовка HTML, такой как кодировка, файл CSS или JavaScript. Смотрите следующий фрагмент:

<%@ 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>
<Голова>
<link rel = "stylesheet" href = "/your__project/struts/xhtml/styles.css" type = "text/css"/>
<script src = "/your__project/struts/utils.js" type = "text/javascript"> </script>
</HEAD>
<Тело>
..

Чтобы добавить новый файл js или css, просто добавьте его в файл шаблона « template \ xhtml \ head.ftl » и выведите его с помощью тега <s: head> .

На самом деле этот тег <s: head> не требуется размещать сверху и деформировать с помощью тега HTML <head>, например

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

Вы можете поместить его куда угодно, он просто выведет путь к файлу CSS и js (по умолчанию в теме 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> .