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 <jsp:invoke> for Tag files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<jsp:invoke> for Tag files" Watch "<jsp:invoke> for Tag files" New topic

<jsp:invoke> for Tag files

namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
In Q#19 (chapter#10) of HFSJ second edition, I couldn't find explaination about <jsp:invoke> and variable used as a directive in Tag file anywhere in the book.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

I can't tell if there's one or not, but you can find an explanation in the JSP specification.

[My Blog]
All roads lead to JavaRanch
rachna jain
Ranch Hand

Joined: Jul 14, 2009
Posts: 76

Following is the explanation -

I have taken this from jsp 2.0 spec please refer that

JSP.5.12 <jsp:invoke>
The <jsp:invoke> standard action can only be used in tag files (see
Chapter JSP.8, “Tag Files”), and must result in a translation error if used in a JSP.
It takes the name of an attribute that is a fragment, and invokes the fragment,
sending the output of the result to the JspWriter, or to a scoped attribute that can be
examined and manipulated. If the fragment identified by the given name is null,
<jsp:invoke> will behave as though a fragment was passed in that produces no
JSP.5.12.1 Basic Usage
The most basic usage of this standard action will invoke a fragment with the
given name with no parameters. The fragment will be invoked using the JspFragment.
invoke method, passing in null for the Writer parameter so that the results
will be sent to the JspWriter of the JspContext associated with the JspFragment.
The following is an example of such a basic fragment invocation:
<jsp:invoke fragment=”frag1”/>
JSP.5.12.2 Storing Fragment Output
It is also possible to invoke the fragment and send the results to a scoped
attribute for further examination and manipulation. This can be accomplished by
specifying the var or varReader attribute in the action. In this usage, the fragment
is invoked using the JspFragment.invoke method, but a custom is
passed in instead of null.
If var is specified, the container must ensure that a java.lang.String object is
made available in a scoped attribute with the name specified by var. The String
must contain the content sent by the fragment to the Writer provided in the Jsp-
Fragment.invoke call.
If varReader is specified, the container must ensure that a
object is constructed and is made available in a scoped attribute with the name
specified by varReader. The Reader object can then be passed to a custom action
for further processing. The Reader object must produce the content sent by the
JavaServer Pages 2.0 Specification
fragment to the provided Writer. The Reader must also be resettable. That is, if its
reset method is called, the result of the invoked fragment must be able to be read
again without re-executing the fragment.
An optional scope attribute indicates the scope of the resulting scoped
The following is an example of using var or varReader and the scope attribute:
<jsp:invoke fragment=”frag2” var=”resultString” scope=”session”/>
<jsp:invoke fragment=”frag3” varReader=”resultReader” scope=”page”/>

Rachna Jain
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Thanks a lot Rachana.
I agree. Here's the link:
subject: <jsp:invoke> for Tag files
It's not a secret anymore!