Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scripting elements in JspFragment

 
Vijay P
Greenhorn
Posts: 8
  • 0
  • 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 " %>
</c:forEach>
 
salil verma
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just check out this code this may be helpful to understand the thing

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

<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="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">
<TITLE>Test1.jsp</TITLE>
</HEAD>
<BODY>
<jsp:include page="Test.jspf">
<jsp aram name="test" value="First Paramter" />
<jsp aram name="second" value="Second Paramter"/>
</jsp:include>
</BODY>
</HTML>


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


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



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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • 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
Greenhorn
Posts: 8
  • 0
  • 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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic