Meaningless Drivel is fun!
The moose likes JSP and the fly likes Custom JSP tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom JSP tags" Watch "Custom JSP tags" New topic

Custom JSP tags

Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 68
I have a question about implementing a class for a custom tag that extends BodyTagSupport. If the doStartTag() method returns EVAL_BODY_BUFFERED I know a BodyContent object is automatically created and the doInitBody() and doAfterBody() methods are called. The doAfterBody() method I'm looking at will get a JspWriter and write out the BodyContent. My question is I don't see where data is added to the BodyContent object. There is some code in the doInitBody() and doAfterBody() that can call pageContext.setAttribute() with data to be displayed by the JSP page. Does these calls to pageContext.setAttribute() cause the data to be saved in the BodyContent object?

Stefan Evans

Joined: Jul 06, 2005
Posts: 1580

The setting of the body is done by the servlet container you are running in.
It is doing stuff in the background and just every now and again consulting you to find out what you want to do with it.

According to the lifeCycle it will setBodyContent() before calling doInitBody()
It will then call evaluate the body, and call doAFterBody()

The logic around setting the body and evaluating it is internal to the servlet container
I agree. Here's the link:
subject: Custom JSP tags
It's not a secret anymore!