JSP / Custom Tag Libraries

Discussion in 'Java' started by JStrummer, May 20, 2004.

  1. JStrummer

    JStrummer Guest

    I am writing my first page in JSP and am trying to get my arms around
    custom tag libraries.

    What I'd like to do is mimic an ASP-type subroutine here, where I call
    a subroutine, pass in a parameter, and output HTML code. For instance,
    in ASP, writePageTitle("My homepage") would yield <TITLE>My
    homepage</TITLE>.

    I am having problems passing the parameter to a tag file in JSP. Here
    is what I have. I would appreciate any pointers, and, if I am going
    about this the wrong way, I am very, very open to suggestion. Thanks
    in advance.

    index.jsp
    ==================
    <HTML>
    <HEAD>
    <c:set var="PageKeywords" value="Home, Homepage, Main Page" />
    <c:set var="PageTitle" value="Home" />

    <%@ taglib prefix="HTMLTitle"
    tagdir="/WEB-INF/tags" %>
    <HTMLTitle:html_title/ PageTitle="<%=PageTitle%>">

    and so on....

    html_title.tag
    ===================
    <%
    out.println("<TITLE>${PageTitle}</TITLE>");
    %>
     
    JStrummer, May 20, 2004
    #1
    1. Advertising

  2. JStrummer

    Sudsy Guest

    JStrummer wrote:
    > I am writing my first page in JSP and am trying to get my arms around
    > custom tag libraries.
    >
    > What I'd like to do is mimic an ASP-type subroutine here, where I call
    > a subroutine, pass in a parameter, and output HTML code. For instance,
    > in ASP, writePageTitle("My homepage") would yield <TITLE>My
    > homepage</TITLE>.
    >
    > I am having problems passing the parameter to a tag file in JSP. Here
    > is what I have. I would appreciate any pointers, and, if I am going
    > about this the wrong way, I am very, very open to suggestion. Thanks
    > in advance.


    Oh boy! You are so far away from how custom tags work that I would
    suggest running, not walking, to your nearest computer book store
    and picking up "Advanced JavaServer Pages" by David Geary (ISBN
    0-13-030704-1).
    First of all, your taglib statement should read like this:
    <%@ taglib uri="some_uri" prefix="some_prefix" />
    Then, some_uri has to be declared in your web.xml file, vis:
    <taglib>
    <taglib-uri>some_uri</taglib-uri>
    <taglib-location>some_file.tld</taglib-location>
    </taglib>
    In that file you will find the tag definitions, hence the tld
    (tag library definition) file extension. There you will find
    the connection to the actual Java class, something like this:
    <tag>
    <name>some_tag_name</name>
    <tagclass>tag_class_name</tagclass>
    ...
    </tag>
    Finally, you'll have to find tag_class_name in one of the
    jars known to the web application, i.e. in WEB-INF/lib, or
    as a stand-alone file in the WEB-INF/classes directory tree.
    This class will typically extend either TagSupport or
    BodyTagSupport...
    There's a lot at play here. You're trying to use the facility
    as if it was simply a matter of including content. Sorry, but
    it's a bit more complicated than that.
     
    Sudsy, May 20, 2004
    #2
    1. Advertising

  3. JStrummer

    Ryan Stewart Guest

    "Sudsy" <> wrote in message
    news:...
    > JStrummer wrote:
    > > I am writing my first page in JSP and am trying to get my arms around
    > > custom tag libraries.
    > >
    > > What I'd like to do is mimic an ASP-type subroutine here, where I call
    > > a subroutine, pass in a parameter, and output HTML code. For instance,
    > > in ASP, writePageTitle("My homepage") would yield <TITLE>My
    > > homepage</TITLE>.
    > >
    > > I am having problems passing the parameter to a tag file in JSP. Here
    > > is what I have. I would appreciate any pointers, and, if I am going
    > > about this the wrong way, I am very, very open to suggestion. Thanks
    > > in advance.

    >
    > Oh boy! You are so far away from how custom tags work that I would
    > suggest running, not walking, to your nearest computer book store
    > and picking up "Advanced JavaServer Pages" by David Geary (ISBN
    > 0-13-030704-1).

    Ditto that.

    *snip*
    > In that file you will find the tag definitions, hence the tld
    > (tag library definition) file extension. There you will find

    Actually, tag library descriptor.

    *snip*
    > There's a lot at play here. You're trying to use the facility
    > as if it was simply a matter of including content. Sorry, but
    > it's a bit more complicated than that.

    Ditto again. In my experience, JSP is almost infinitely more structured than
    ASP. You can't just sling parts together and expect it to give some result.
     
    Ryan Stewart, May 20, 2004
    #3
  4. JStrummer

    kaeli Guest

    In article <>,
    enlightened us with...
    >
    > Oh boy! You are so far away from how custom tags work that I would
    > suggest running, not walking, to your nearest computer book store
    > and picking up "Advanced JavaServer Pages" by David Geary (ISBN
    > 0-13-030704-1).


    I agree.
    I found this site to be very useful when I was learning taglibs. It has
    usable code to play with, too.

    http://www.orionserver.com/tutorials/taglibs/

    --
    --
    ~kaeli~
    Jesus saves, Allah protects, and Cthulhu thinks you'd make
    a nice sandwich.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
     
    kaeli, May 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GA
    Replies:
    0
    Views:
    856
  2. Lukasz Indyk
    Replies:
    1
    Views:
    1,517
    Andrew Thompson
    Sep 22, 2004
  3. shruds
    Replies:
    1
    Views:
    966
    John C. Bollinger
    Jan 27, 2006
  4. Karsten Wutzke
    Replies:
    21
    Views:
    948
    Roedy Green
    Jun 29, 2007
  5. zalek
    Replies:
    1
    Views:
    300
    zalek
    Jul 17, 2008
Loading...

Share This Page