Quoting Joe Lei ([EMAIL PROTECTED]):
> can someone give an example of a servlet using a servlet template technique,
> i did want to learn how it works.

There are working examples in the free WebMacro distribution, you could
try those out, look at them, etc.

But briefly, if you have this as your template:

     <html>....$cust.Name...</html>

and you have this class:

     public Customer { public String getName(); }

then you do this:

     Writer out = whereMyDataGoes();
     Customer c = findMyData();

     Template tmpl = WebMacro.getTemplate("template.name.here");

     Hashtable context = new Hashtable(); // what the template can see
     context.put("cust", context);        // put your data in hashtable

     tmpl.execute(out, context);          // fill in the blanks

and the template system takes care of the rest. It looks in the hashtable
and finds your Customer, analyzes it to figure out that the Name property
can be extracted via the getName() method, fills in the $cust.Name in
the template, and writes the resulting HTML to the supplied output stream.

The template can have conditional logic, loops, etc., in it, you should
see the examples in the WebMacro distribution for more detailed examples.

Justin

- - -
WebMacro Servlet Framework
http://webmacro.org

Quoting Joe Lei ([EMAIL PROTECTED]):
> can someone give an example of a servlet using a servlet template technique,
> i did want to learn how it works.
>
> ----- Original Message -----
> From: Justin Wells <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, November 16, 1999 1:51 PM
> Subject: Re: Servlet Template vs. JSP
>
>
> > Quoting Steve Buonincontri ([EMAIL PROTECTED]):
> > > What are servlet templates? are they presentation templates?
> > >
> > > - steve
> >
> > A servlet template is an object that processes text "filling in the
> > blanks" with values from some data set. The idea is to use it to
> > produce HTML:
> >
> >    <html>....$someVariable..<tag>$someOtherVariable</tag>...</html>
> >
> > Most template systems also have the ability to do some basic flow
> > control, conditional logic, etc., and some go further than that. A
> > template typically does not allow you to insert arbitrary Java code,
> > but limits itself to generating HTML.
> >
> > The idea is that your code is cleaner and easier to read if there is
> > no HTML strewn through it, and similarly the HTML is easier to edit
> > if it is not embedded in code.
> >
> > WebMacro is an example of a template system that is free:
> >
> >    http://webmacro.org
> >
> > In addition to the above, WebMacro also performs bean-style class
> > analysis to work out how to extract properties from regular objects,
> > so that as the program you don't have to work out the mapping yourself.
> >
> > Obviously I'm biased, since I'm the principal author of WebMacro. Other
> > similar systems are FreeMarker, and also I believe that Enhydra has one.
> > They don't do the class analysis, but are largely equivalent to WebMacro
> > in other respects.
> >
> > One key point about template systems as opposed to JSP is that the
> > template system is under your control as the Java programmer in the
> > servlet: you can choose when and how you want to use it, you aren't
> > forced to use it all the time--even within the same servlet you could
> > use it sometimes and not others.
> >
> > Justin
> >
> > ---
> > WebMacro Servlet Framework
> > http://webmacro.org
> >
> >
> ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to