Fork me on GitHub
Edit on GitHub << back to Tag Reference

webjar

Available since Struts 7.3.0.

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

Resolves a version-less WebJar resource path to a servable URL and writes it to the output (or stores it in a variable when var is set). For example, bootstrap/css/bootstrap.min.css is resolved to <ctx>/static/webjars/bootstrap/5.3.8/css/bootstrap.min.css, so you never hardcode the WebJar version in your templates.

The tag emits a plain URL string, so it composes with script, link, or a raw <link> / <script> element. See Static Content for the serving pipeline and configuration constants.

Resolve a version-less WebJar resource path to a servable URL

Attributes

Dynamic Attributes Allowed:

false

Name

Required

Default

Evaluated

Type

Description

path true false String The version-less WebJar resource path, e.g. bootstrap/css/bootstrap.min.css
performClearTagStateForTagPoolingServers false false false Boolean Whether to clear all tag state during doEndTag() processing (if applicable)
var false false String Name used to reference the value pushed into the Value Stack (scope: action).

Examples

Example 1 - reference a WebJar stylesheet:

<link rel="stylesheet" href="<s:webjar path="bootstrap/css/bootstrap.min.css"/>"/>

Example 2 - reference a WebJar script:

<s:webjar var="webjarUrl" path="jquery/jquery.min.js"/>
<s:script src="%{webjarUrl}"/>

Example 3 - FreeMarker macro:

<@s.webjar path="jquery/jquery.min.js"/>
Follow @x