File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Scripting elements in JspFragment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Scripting elements in JspFragment" Watch "Scripting elements in JspFragment" New topic

Scripting elements in JspFragment

Vijay P

Joined: Apr 03, 2000
Posts: 8
(HFSJ PAge 512 - Topic "What exactly is a JspFragment)

This section in book makes a comment "there must NOT be any scripting elements in JspFragment, it can contain template text, standard and custom actions, EL but NO scriptlets, declaration or scripting expression. "

However is in't it true we could use scripting elements inside the body ? How does the above statment hold true against following ?

<c:forEach var="myitem" items="myList">
<%="I am scripting expression " %>

salil verma

Joined: Jun 03, 2006
Posts: 22
just check out this code this may be helpful to understand the thing

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<jsp:include page="Test.jspf">
<jsp aram name="test" value="First Paramter" />
<jsp aram name="second" value="Second Paramter"/>

<p> The first parameter is ${param.test} </p>
<p>The second parameter is ${param.second}</p>

<jsp:include page="test2.jsp"/>

<p> I am in test 2 </p>

Now if you execute the file test1 you will get the expected result . But just change the extension of Test.jsp to Test.jspf. Then try to execute the same.

You will find , while changing the extension of test.jsp to jspf the scripts are the executed. That is the thing they have mentioned in the paragraf.
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

"FastGoogly", we don't have many rules around here but our naming policy is one of them. Not complying with the policy will lead to your account becoming locked. This warning hopefully will prevent that from happening, but some action is required on your part.

Please review the policy here and you can change your Publicly Displayed Name here.

A good workman is known by his tools.
Vijay P

Joined: Apr 03, 2000
Posts: 8
Salil, I am not sure the example explains why you can't have scriptlets in a JspFragment. I did a little bit more digging. As per JSP 2.0 specification

"A translation error must occur if a piece of JSP code that is to be translatedinto a JSP Fragment contains scriptlets or scriptlet expressions."

A SimpleTagSupport uses JspFragment, hence body of a simple tag can not contain scripting.. By that extension body-content for SimpleTag's can not be "JSP", only allowed values are "scriptless", "emptly", "tagdependent".

If I specify the body-content as "JSP" in TLD for a SimpleTagSupport, you will get an error.

Similarly you can not use scripting inside body of a "Tag File".

However a classic tag implemented with BodyTagSupport can contain "scripting " in its body. That is why you are able to include the scripting in standard actions.

Standard action allows scriting to be used in its body.

I agree. Here's the link:
subject: Scripting elements in JspFragment
It's not a secret anymore!