jsptomcatcompilationeltaglib

Who compiles the taglibs?


I'm studying a code that mixes, in one JSP archive: java commands, Expression Language commands and Taglibs. So, I know the Java code is transformed in a Servlet, and the EL is compiled by the servlet container. But what about the taglibs? For example:

<jsp:useBean id="contact" class="package1.package2.contact"/>

Who deals with this code? Or if I put at the beggining of a tagfile:

<%@ attribute name="id" required="true" %>

And in my JSP code, to call this tagfile:

   <caelum:DateField id="bornDate" />

Who is responsible for managing this parameter-passing?


Solution

  • The container is responsible for compiling and processing your JSP page tag files or tag lib files. As we know there are mainly two phases in JSP : 1:- Translation phase 2:- Execution phase

    When you mention like below in JSP tag file

    <%@ attribute name="id" required="true" %>
    

    the container will translate your tag file into a class that implement SimpleTag interface. And whenever your tag file is being invoked doTag() method of translated class will be invoked and when you mention <%@attribute> (any directive) means you are giving special instruction to the container and then the container will translate it at translation time change translated class as required.

    At the end for every tag, whether it is a standard action, tag file, or a custom tag, Tag handler classes are invoked by the JSP container.

    And

    <caelum:DateField id="bornDate" />
    

    For the above tag, there must be a Tag Handler class(maybe written by you) that extends either SimpleTagSupport class or TagSupport class and there must be a tag file associated with the implemented class. So to handle the id attribute
    1:- You have to mention <attribute> element in your .tld file. 2:- Make getter and setter for id attribute in your tag handler class.

    When the above tag gets executed corresponding tag handler class will be invoked and setId() method will be called.

    This is a very short explanation. There is a lot more to understand like data type conversion etc. Better to go with the Head First Servlet Jsp book.