Niall's revised example is *almost* right. Here's a fixed version of it:
<html>
<head><title>Hello</title></head>
<body>
<h1>
<% if (request.getParameter("name") == null) %>
Hello World
<% else %>
Hello, <%= request.getParameter("name") %>
</h1>
</body></html>
The difference is that in order to print out the name parameter, you need to
use an expression rather than a scriptlet (i.e. <%= ... %> rather than <%
... %>).
Of course, with Struts, you could write this without scriptlets altogether:
<html>
<head><title>Hello</title></head>
<body>
<h1>
<logic:notPresent parameter="name">
Hello World
</logic:notPresent>
<logic:present parameter="name">
<bean:parameter id="name" name="name"/>
Hello, <bean:write name="name"/>
</logic:present>
</h1>
</body></html>
Hope this helps.
--
Martin Cooper
----- Original Message -----
From: "Niall Pemberton" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Sunday, March 04, 2001 11:55 AM
Subject: You make the decision Velocity/Turbine vs. Struts/JSP
> Jon,
>
> http://jakarta.apache.org/velocity/ymtd/ymtd.html
>
> I read your comparison of Turbine/Velocity and Struts/JSP and although
> you state it your aim to be "fair and unbiased", I think you failed
> since most of your examples, although sytanctically correct, were poor
> examples of the use of Struts and Jsp. I only started getting into Jsp &
> Struts a couple of weeks ago but below are my comments on your article.
> I also copy this to the struts mailing list as I am sure more
> experienced people may be able to comment better.
>
>
> In your first example "Saying Hello" there is not need whatsoever in Jsp
> to have any "out.println" statements. The example you gave could have
> been coded in the following way:
>
> <html>
> <head><title>Hello</title></head>
> <body>
> <h1>
> <% if (request.getParameter("name") == null) %>
> Hello World
> <% else %>
> Hello, <% request.getParameter("name") %>
> </h1>
> </body></html>
>
>
> On the subject of "Generation", I don't believe this is a big issue,
> since 1) its automatically handled by the servlet container and
> therefore not a big issue to developers and 2) the performance issue is
> only relevant when you change the application, its not like it happens
> every time you run the jsp.
>
> On the subject of "Error Handling", you are comparing Velocity only with
> Jsp - the idea of Struts is that, it takes the need for Scriptlets out
> of Jsp by providing custom tags (java classes) to deal with those
> situations. What you quote here from Jason's books is only relevant to
> Scriptlets, not well written Struts applications. The issues stated
> there are exactly why a framework such as Struts was developed and an
> argument for using Struts.
>
> Again in the section of "JavaBeans" you are not comparing
> like-with-like. Velocity/Turbine will have the same issues of "Scope"
> that any Web Application has and from what I see of your
> Velocity/Turbine example, you have just hidden this from the Web
> Designer. The same can be done in a Struts application with Struts tags
> rather than the "<jsp:useBean>" tag. Again your quote from Jason's book
> relates solely to Jsp and is not a fair comparison to Struts.
>
> I'll ignore the sample app section, again its Jsp not Struts.
>
> The "Taglibs" section is the first serious section which deals with
> Struts and you start with cheap points about "cutting edge of a broken
> wheel" - so tell me how is Velocity cutting edge then? - yet another
> scripting language to handle presentation that a Web Designer needs to
> get to grips with. The idea with Jsp/Struts is that it extends HTML in
> the same "style" to what Web Designers are used to.
>
> I would be the first to say the Struts documentation could be better but
> the two examples that you listed from the Struts documentation were
> small examples used to illustrate specific Struts features and not the
> best way to develop Struts applications on the Model 2 architecture. The
> first example using the <logic:equal> tag is poor because it
> encapsulates the "business logic" (I know its simple) of the app in the
> presentation and therefore shouldn't have been in the Jsp. Complex logic
> shouldn't be in the presentation layer and so their use should be
> limited. The "if. . . .else" logic of Velocity looks good to me, as a
> programmer, but I think a Web Designer would be more at home with the
> Tag Style they are used to.
>
> In your second example from the Struts document which uses a Scriptlet
> to define an ArrayList - this has clearly been done to make the example
> simple (a point I seem to remember being made in the document, though I
> couldn't find the example again) - it is a break from the MVC
> architecture but its not how Struts should be used, this collection
> would have been created in the "logic" java end and put into scope ready
> for a Web Designer to use through Struts tags - as simple or simpler
> than the Velocity example.
>
> And finally - the example from "Jason Hunters" book which you say has
> been entirely implemented as a Struts app - this is awful and is a
> complete abuse of everything that Struts is about - why not get a decent
> Struts developer (not me!) of giving you a good example - also where is
> the Velocity equivalent for fair comparison - nowhere to be seen!
>
> I was hoping for an article which would help me make an informed
> decision but your portrayal of Struts didn't show it in the way it
> should be used or explain what else it could do, such as
> Internationalization. I understand (but not like) commercial software
> vendors going to any means to disparage a competitors product but I am
> shocked that one Open Source project has done it to another when they
> both come under the same Apache umbrella.
>
> Niall