Quoting Tin Pham <[EMAIL PROTECTED]>:

> Wow that great Craig. Thanks for taking the time to give me some hints.
> 
> I did not know that the servlets 2.4 would let me do that. I really like
> that one. I can then have pockets of xml on my page. I will check this
> option out first.
> 

Filters on request dispatcher calls are very cool ... but my absolute favorite
feature of the new technologies (Servlet 2.4 and JSP 2.0) is that you can now
use EL expressions everywhere in a JSP page, not just in tag attributes of tags
that understand them (like JSTL tags, and the struts-el tags).

This applies to the "do an XSLT transformation" scenario quite nicely, once you
remember that a JSP 2.0 page can be an XML document (or an XML document can be
a JSP 2.0 page, depending on how you want to look at it :-).  Just as an
example of this, I've been playing with an application that grabs news items
from a database and renders them in RSS ... the cute trick being that the
client can request whichever RSS version they want.  I did this by having the
output from the app be a JSP page in a fairly generic format:

  <channel
   xmlns:c="http://java.sun.com/jstl/core";
   about="${channel.aboutURL}">
      <title>${channel.title}</title>
      <link>${channel.linkURL}</link>
      <description>
            ${channel.description}
      </description>
      ... more per-channel stuff ...
      <!-- "c" is the JSTL core tag library from above -->
      <c:forEach items="${channel.items}" var="item">
          <item about="${item.aboutURL}">
              <title>${item.title}</title>
              <link>${item.linkURL}</link>
              <description>
                  ${item.description}
            </description>
            ... more per-item stuff ...
          </item>
      </c:forEach>
  </channel>

and used a different stylesheet to reformat this to 0.9, 0.91, 1.0, or 2.0
standards.  The EL expressions pulled in the dynamic parts of the data from my
channel and item beans, with the static parts forming the standard structure of
my generic XML (with elements and attributes set up the way my stylesheets
expect them).  If you're not an XSLT guru, it would also be pretty easy to
create a different JSP page for each of the four supported RSS versions, and
use something like a different ActionForward for each of them to select the
version.

This is a *ton* easier than dynamically constructing XML in Java :-).

Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to