On Tue, 17 Sep 2002, Erik Beijnoff wrote:

> But then when it should be printed... The page variable myUrl is
> printed in the <a/> elements href attribute with href=’<c:out
> value="${myUrl}"/>’!?!?
>
> I mean this isn't even correct xml in any way. Even if the <c:out>
> would have been just plain text, which it isn't, it still quite ugly.
> But it's even worse, as far as I know "<" isn't even allowed in an
> attribute, even less so trying to nest an xml document element
> hierarchy within it!

Indeed, the syntax isn't valid XML.  However, documents that produce web
pages -- or even XML documents -- need not be authored in XML.  If you're
comfortable with the syntax and don't need to parse the input document,
there's nothing wrong with

  <a href="<c:out value="${myUrl}"/>"/>

This turns into

  <a href="http:///."; />

at request-time, so all the client sees is valid HTML (or XML if that's
how you've written your page).

Still, the syntax is indeed awkward.  There are a number of potential
solutions:

 * You can author an JSP page in the XML syntax and use CDATA to indicate
   that "<a href=" and "/>" are simply text.
 * In JSP 2.0, you'll be able to write

    <a href="${myUrl}" />

   which is valid XML.
 * In JSP 2.0, you'll also be able to construct the <a> element manually
   using tags in the "jsp" namespace, much as you'd do in XSLT.

As an side, note that you should really output URLs with <c:url>, not
<c:out> -- but that doesn't address the syntax you're pointing out.

> So what I'm asking is this: is there any other (better) way to perform
> this action, perhaps with a tag <myTag:hyperLink value="${myUrl}"/> or
> something like that. But shouldn't this really have been in the spec?
> Any opinions?

We really couldn't have added this to JSTL, since one of the goals was to
avoid tying JSTL to HTML in particular.  Instead, we adopted a longer-term
view, realizing that the problems would be fixed automatically under JSP
2.0.  To put it another way, this is really a JSP issue, not a JSTL issue,
and it's fixed in the upcoming version of JSP.

Thanks for the great comments about JSTL!  It's great to hear you're
finding the spec useful.  Best,

--
Shawn Bayern
JSTL reference-implementation lead
"JSTL in Action"   http://www.jstlbook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to