On Sun, Mar 04, 2001 at 08:11:31PM -0800, Martin Cooper wrote:
> 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


I think the "canonical" solution in JSP is something like this:

---
<jsp:usebean id="name" scope="request" type="java.lang.String">
  <jsp:setProperty name="name" value="Word" />
</jsp:usebean>

<html>
<head><title>Hello</title></head>
<body>
<h1>
Hello <%= name %>
</h1>
</body></html>
---

On the other hand I do share Jon Stevens' views that this syntax
is really not for page design people.                      incze

Reply via email to