• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Scripting elements in JspFragment

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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 " %>
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
Vijay P
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

My cellmate was this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic