Dror Matalon wrote:
> Hans,
>
> I just read the article which is very interesting for people that want
> to use libraries to develop JSTL style tags.
>
> In reading the article, I realized that I had a nagging question
> about JSTL, tag libraries, etc vs JSP.

Before I answer, let's just clarify what "JSTL vs JSP" means. JSTL is
defined as a tag library that can be implemented (by anyone, but
typically by container implementors) using the standard JSP API for
custom tag libraries. So there's really no "JSTL vs JSP"; using JSTL
_is_ using JSP, just as using the standard <jsp:useBean>, scriptlets,
etc. means using JSP.

The only difference between JSTL and any other tag library is that JSTL
is defined by a spec, and therefore more likely to be supported by all
containers (eventually) without having to install it. This also means
that a container vendor can choice to support it by generating highly
optimized code when converting a JSP page to a servlet, e.g. generate
a regular Java if statement instead of calls to the tag handler for
<c:if>.

With this in mind, I therefore assume that you really wonder about
"using custom tag libraries, such as JSTL, vs using Java code in
scriptlets" based on your comments below. That's a fair question (even
though it's been asked and answered many times on this list and
elsewhere ;-)

> To quote from your article some code:
>
> ----------------------------------------
> <table>
>    <xmp:forEachDay var="curr">
>       <c:set var="bg" value="white" />
>       <xmp:ifSunday>
>          <c:set var="bg" value="red" />
>       </xmp:ifSunday>
>       <tr bgcolor="<c:out value="${bg}" />">
>          <td>
>             <fmt:formatDate value="${curr.time}"
>                pattern="EE dd, MMM yyyy" />
>          </td>
>       </tr>
>    </xmp:forEachDay>
> </table>
> ----------------------------------------
>
>
> Is JSTL clearly easier than JSP? I'll admit that I'm biased. As
> someone who know Java this looks more complicated than doing the
> same or similar things with JSP. But rather than use anecdotal
> evidence one way or another I'd be intrested in more systematic
> research on this.

The best way I can answer this question is to show how this
example can be written with Java code in scriptlets instead:

  <%
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    int thisMonth = calendar.get(Calendar.MONTH);
    int currMonth = thisMonth;
    int currDay = calendar.get(Calendar.DAY_OF_MONTH);
    SimpleDateFormat dateFormat = new SimpleDateFormat("EE dd, MM yyy");
  %>
  <table>
    <%
      while (currMonth == thisMonth && currDay <= lastDay) {
        String bg = "white";
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
          bg = "red";
        }
    %>
    <tr bgcolor="<%= bg %>">
      <td>
        <%= dateFormat.format(calendar.getTime()) %>
      </td>
    </tr>
    <%
        calendar.set(Calendar.DAY_OF_MONTH,
          calendar.get(Calendar.DAY_OF_MONTH) + 1);
        currMonth = calendar.get(Calendar.MONTH);
        currDay = calendar.get(Calendar.DAY_OF_MONTH);
      }
    %>
  </table>

Which version looks looks easier to you? The, of course, answer
depends on your background. In both versions, it's clearly
"programming"; the primary difference is syntax, but there are also
a few other important differences:
1) Code size
   The scripting version is double the size of the JSTL version
   (30 lines vs 14 lines)
2) Knowledge requirements
   For the scripting version I need to know about the Calendar and
   how to set and get its values, and the SimpleDateFormat class.
   For the JSTL version, I need to know about the custom tags,
   their attributes, and the properties of the exposed data I can
   access using the EL.
3) Syntax error handling
   With the scripting version, if I make a syntax error, I get cryptic
   javac error messages (e.g. "'catch' without 'try'") with line
   numbers that refer to the generated servlet source code.
   With the JSTL version, I (mostly) get error messages that identify
   the custom action and attribute names with line numbers that refer
   to the JSP page source.
4) Development tools
   If I put the Java code (custom actions, beans) in standard class
   files, I can develop the code with a regular Java IDE or syntax
   aware text editor (e.g. emacs), and debug it using standard Java
   debuggers.
   If I put the Java code in the JSP pages, I need special tools that
   understands both Java and JSP syntax.

So, even if you really know Java, I think the above shows that using
JSTL and other custom actions still have advantages. And if you're
new to Java and primarily want to get some dynamic web pages working,
there's no doubt that using custom actions and JSTL saves you from a
lot of headaches ;-)

As a side note I can say that, even though I've been a programmer for
more than 20 years, the last 5 or so in Java, it took me a lot longer
to write the Java scriptlet version than the JSTL version, and I made a
number of silly mistakes along the way (resulting in syntax errors and
even infinite loops).

> Do you know of any focus groups or other research to compare how
> long/hard it is to get people up to speed with JSTL/Tags vs standard
> JSP.  How about vs ASP, PHP and other competing technologies?

It's not exactly what you ask about, but there's a project starting
up at the URL below to compare different web application development
frameworks:

  <http://www.waferproject.org/index.html>

The last time I looked, they hadn't got very far, but you may want to
join them and help out.

> On a similar note, there's been a recent presentation made comparing
> these different technologies by a yahoo engineer explaining why, at
> least for some projects, they're migrating to PHP.
> http://public.yahoo.com/~radwin/talks/yahoo-phpcon2002.htm
>
> The only reasons they mention against Java/JSP is that native thread
> support on FreeBSD is not available yet.

Right, I saw that. It's not really related to this issue, though.

> Thanks for the article and any responses,

You're welcome.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
JavaServer Pages        http://TheJSPBook.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