Note that there are some explanatory texts on larger screens.

plurals
  1. POJSP tags + scriptlet. How to enable scriptlet?
    primarykey
    data
    text
    <p>I have a page which uses a tag template. My web.xml is very basic.</p> <p>I simply want to run some code in the page.<br> And no, I'm not interested in tags or other alternative. I want to use the bad-practice scriptlet haha.</p> <p>So far I'm getting this "HTTP ERROR 500" error:</p> <pre><code>Scripting elements ( %!, jsp:declaration, %=, jsp:expression, %, jsp:scriptlet ) are disallowed here. </code></pre> <p>While my files look like:</p> <p>/WEB-INF/web.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;/web-app&gt; </code></pre> <p>/WEB-INF/tags/wrapper.tag</p> <pre><code>&lt;%@tag description="Simple Wrapper Tag" pageEncoding="UTF-8"%&gt; &lt;%@ attribute name="title" required="true" type="java.lang.String"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;${title}&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;jsp:doBody /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>index.jsp</p> <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@taglib prefix="t" tagdir="/WEB-INF/tags"%&gt; &lt;t:wrapper&gt; &lt;jsp:attribute name="title"&gt;My nice title&lt;/jsp:attribute&gt; &lt;jsp:body&gt; &lt;h1&gt;&lt;%="some code generated text"%&gt;&lt;/h1&gt; &lt;/jsp:body&gt; &lt;/t:wrapper&gt; </code></pre> <p>I have tried to modify web.xml to explicitly enable it, like this (not working):</p> <pre><code>&lt;jsp-config&gt; &lt;jsp-property-group&gt; &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt; &lt;scripting-invalid&gt;false&lt;/scripting-invalid&gt; &lt;/jsp-property-group&gt; &lt;jsp-property-group&gt; &lt;url-pattern&gt;*.tag&lt;/url-pattern&gt; &lt;scripting-invalid&gt;false&lt;/scripting-invalid&gt; &lt;/jsp-property-group&gt; &lt;/jsp-config&gt; </code></pre> <p>So, how do I use pure scriptlets within my tag'ed JSP?</p> <p><strong>EDIT #1</strong>:</p> <p><strong>An ideal code would look like this</strong>, inside a page that uses my template ('wrapper' as the above):</p> <pre><code>&lt;%@page import="java.util.Calendar"%&gt; &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@taglib prefix="t" tagdir="/WEB-INF/tags"%&gt; &lt;t:wrapper&gt; &lt;jsp:attribute name="title"&gt;My nice title&lt;/jsp:attribute&gt; &lt;% final int day_of_week = Calendar.getInstance().get( Calendar.DAY_OF_WEEK); if (day_of_week == Calendar.SATURDAY) { %&gt; &lt;jsp:body&gt; &lt;h1&gt;Have a nice Saturday (&lt;%=Integer.toString(day_of_week)%&gt;)!&lt;/h1&gt; &lt;/jsp:body&gt; &lt;% } else { %&gt; &lt;jsp:body&gt; &lt;h1&gt;Have a nice rest-of-the-week (&lt;%=Integer.toString(day_of_week)%&gt;)!&lt;/h1&gt; &lt;/jsp:body&gt; &lt;% } %&gt; &lt;/t:wrapper&gt; </code></pre> <p>See? Scriptlets between &amp; inside the '' tags. That's exactly what I'm trying to achieve.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload