Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP / Custom Tag Libraries

Reply
Thread Tools

JSP / Custom Tag Libraries

 
 
JStrummer
Guest
Posts: n/a
 
      05-20-2004
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>");
%>
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      05-20-2004
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.

 
Reply With Quote
 
 
 
 
Ryan Stewart
Guest
Posts: n/a
 
      05-20-2004
"Sudsy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
kaeli
Guest
Posts: n/a
 
      05-20-2004
In article <(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie - problem with JSP tag libraries zalek Java 1 07-17-2008 11:07 AM
Using mandatory libraries (custom class loading vs. expanding libraries) Karsten Wutzke Java 21 06-29-2007 09:25 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
how to write jsp custom tag that can have all kind of jsp elements(not only other tags but also srciplets) in his body Lukasz Indyk Java 1 09-22-2004 12:43 PM
jsp custom tag libraries for weblogic GA Java 0 07-03-2003 01:41 AM



Advertisments