sreehari
sreehari

Reputation: 189

What is the purpose of EVAL_BODY_AGAIN, SKIP_BODY and EVAL_BODY_INCLUDE

I am pretty new to custom tag creation in JSP. When I went through some tutorials, I saw them using EVAL_BODY_AGAIN, SKIP_BODY and EVAL_BODY_INCLUDE tags. Can anyone tell me what it actually means and what is it for?

Upvotes: 1

Views: 3142

Answers (1)

vinay j
vinay j

Reputation: 305

SKIP_BODY : It is an optional returned value but this value must be returned by doStartTag() when you want to skip the body evaluation that is it must be returned when the TagLibraryDescriptor file contains the element empty, the value "empty" shows that there will always be an empty action.

EVAL_BODY_INCLUDE : It is an optional returned value but this value must be returned by the doStartTag() when you want to evaluate the body.

Example :

consider a class DoStartTagExample.java

package pack;

import javax.servlet.jsp.tagext.TagSupport;

public class DoStartTagExample extends TagSupport
{ 
public int doStartTag()
{
//return EVAL_BODY_INCLUDE;
return SKIP_BODY;
} 
}

This is a sample tld called doStartTagExample.tld

<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<tag>
<name>doStart</name>
<tag-class>pack.DoStartTagExample</tag-class> 
<body-content>empty</body-content> 
</tag>
</taglib>

now write a jsp doStartTagExample.jsp

<%@taglib uri="/WEB-INF/doStartTagExample.tld" prefix="dev" %>
<html>
<head>
<title>doStartTag() Example</title>
</head>
<body>
Jsp page content before starting tag.
<dev:doStart>
<br><b>contents displayed after the custom tag's
start tag is encountered.</b>
</dev:doStart>
<br>Jsp page content after closing tag.
</body>
</html>

Output will be as follows

enter image description here

Upvotes: 4

Related Questions