Question

I have disabled scriptlet in all my JSPs in web.xml:

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <scripting-invalid>true</scripting-invalid>
    </jsp-property-group>
</jsp-config>

But I need to import some custom tagLibs which are being used like this:

<%@ taglib prefix="utils" uri="/tags-utils" %>

How do I import that without using scriptlet? Also, how do I avoid using the following?

<%@ page language="java" contentType="text/html; charset=UTF-8" %>

The decision of scriptlet removal is to avoid the scriptlet mess in a project written by more than one developer.

If it is not possible to change the import without using scriptlet then how I would disable it for any use other than <%@ taglib or <%@ page?

Tried to change from

<%@ taglib prefix="s" uri="/struts-tags" %>

to

<jsp:directive.tagLib prefix="s" uri="struts-tags" />

but Servlet throws me an error:

[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/portal].[jsp]] (http-localhost-127.0.0.1-80-3) Servlet.service() for servlet jsp threw exception: org.apache.jasper.JasperException: /index.jsp(2,18) <jsp:directive.tag directive can only be used in a tag file

Is there anything else I have to do?

Was it helpful?

Solution

JSP 2.2 Spec

JSP 1.3.10.1 EBNF Grammar for JSP Syntax

ScriptlessBody ::= ( ( ‘<%--’ JSPCommentBody )
                   | ( ‘<%@’ DirectiveBody )
                   | ( ‘<jsp:directive.’ XMLDirectiveBody )
                   | ( ‘<%!’ <TRANSLATION_ERROR> )
                   | ( ‘<jsp:declaration’ <TRANSLATION_ERROR> )
                   | ( ‘<%=’ <TRANSLATION_ERROR> )
                   | ( ‘<jsp:expression’ <TRANSLATION_ERROR> )
                   | ( ‘<%’ <TRANSLATION_ERROR> )
                   | ( ‘<jsp:scriptlet’ <TRANSLATION_ERROR> )
                   | ( ‘${‘ ELExpressionBody )
                   | ( ‘#{‘ ELExpressionBody )
                   | ( ‘<jsp:text’ XMLTemplateText )
                   | ( ‘<jsp:’ StandardAction )
                   ( ( ‘</’ ExtraClosingTag )
                   | ( ‘<‘ CustomAction CustomActionBody )
                   | TemplateText
                   )*

So, when scripting-invalid=true:

Illegal

<%
<%!
<%=
<jsp:scriptlet
<jsp:declaration
<jsp:expression

Legal

<%@
<jsp:directive.
<jsp:

The following is legal:

 <%@ taglib prefix="utils" uri="/tags-utils" %>

As long as the "app context uri" + "/tags-utils" (the taglib's context-relative path) maps to "taglib absolute uri".

Alternatively, you can try:

 <%@ taglib prefix="utils" uri="http://www.mycorp/utiltags" %>  // use your absolute taglib URI

OR

 <%@ taglib prefix="utils" uri="uri_path_relative_to_jsp_uri" %>  // no leading "/"

OR

 <%@ taglib prefix="utils" tagdir="/WEB-INF/tags" %> // include subdir if approp

The following is invented. There's no jsp:directive.tagLib tag defined. Don't use.

 <jsp:directive.tagLib prefix="s" uri="struts-tags" />

Instead of:

 <%@ page language="java" contentType="text/html; charset=UTF-8" %>

Try:

 <%@ page contentType="text/html; charset=UTF-8" %>  // language is for scriptlets

OTHER TIPS

<%@taglib and <%@page are directives, not scriptlets.

Scriptlets would have <%.

Alternatively you can write like this

<jsp:directive.taglib uri="uri" prefix="prefixOfTag" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top