Home > Net >  How to use scripting elements within apache tiles in spring boot
How to use scripting elements within apache tiles in spring boot

Time:11-17

I'm trying to add apache tiles to spring boot.

Whenever I try to put in real jsp code with tags like

<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<tiles:insertTemplate template="/default.jsp" flush="true">
    <% out.println(new java.util.Date()); %>
</tiles:insertTemplate>

This throws this error.

Scripting elements ( &lt;%!, &lt;jsp:declaration, &lt;%=, &lt;jsp:expression, &lt;%, &lt;jsp:scriptlet ) are disallowed here.

I have "scripting-invalid" set to "false" for .jsp and I don't know how to solve this.

Any help or suggestions are appreciated.

CodePudding user response:

Well based on the exception, it seems it is not allowed to have <% %> inside tags

Could you try the following options:

Option 1:

<% request.setAttribute("content", new java.util.Date()); %>
<tiles:insertTemplate template="/default.jsp" flush="true">
    ${content}
</tiles:insertTemplate>

Option 2:

<c:set var="content">
           <% out.println(new java.util.Date()); %>
</c:set>

<tiles:insertTemplate template="/default.jsp" flush="true">
    ${content}
</tiles:insertTemplate>

Please do confirm if this worked for you,

  • Related