You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@velocity.apache.org by Stefan Mutschlechner <S....@uts-italia.it> on 2008/05/28 10:22:00 UTC

Probelm with template

I'm really new by working with velocity, and servelets.

I'm able to start function witch uses a template to create a html code.

 

 

try 

      {

              /*  first, get and initialize an engine  */

              VelocityEngine ve = new VelocityEngine();

              //ve.init("C:/Programme/Apache Software Foundation/Tomcat
6.0/webapps/examples/WEB-INF/classes/velocity.properties");

              ve.init();      

              /*  next, get the Template  */

              if(ve.templateExists(strtmp))

              {

                  str="Template found !!!!!";

              }

              else

              {

                  str="Template not  found !!!!!";

              }

              Template t = ve.getTemplate(strtmp );

              /*  create a context and add data */

              VelocityContext context = new VelocityContext();

              context.put("name", "World");

              /* now render the template into a StringWriter */

              

              t.merge( context, writer );

              /* show the World */

             // System.out.println( writer.toString() ); 

      }

        catch (Exception e) 

          {

            System.out.print("Error"+ e+"\n");

          }

 

 

 

 

If I have the same source code into a servelet, the servlet don't find
the 

Template.

 

Somebody knows where I can find a small example for this???

I have found more solutions one different websites.

I have tried more of this solutions and its not working.

 

Thanks

 

Stefan Mutschlechner


Re: Probelm with template

Posted by Nathan Bubna <nb...@gmail.com>.
You might find more help on the user@velocity.apache.org list.  This
list doesn't have a lot of subscribers, i think.

Anyway, if you are working with Velocity in a servlet environment, you
should really be using VelocityTools as well.
http://velocity.apache.org/tools/devel/

VelocityTools provides the VelocityViewServlet and other support
classes like the WebappResourceLoader (formerly known as the
WebappLoader), which is probably what you need most right now.
Loading templates reliably in a servlet environment using the default
FileResourceLoader.  For info on how to do that, check the website,
the examples that come with the VelocityTools distribution, and of
course, search the mailing list archives
(http://velocity.markmail.org)

On Wed, May 28, 2008 at 1:22 AM, Stefan Mutschlechner
<S....@uts-italia.it> wrote:
>
> I'm really new by working with velocity, and servelets.
>
> I'm able to start function witch uses a template to create a html code.
>
>
>
>
>
> try
>
>      {
>
>              /*  first, get and initialize an engine  */
>
>              VelocityEngine ve = new VelocityEngine();
>
>              //ve.init("C:/Programme/Apache Software Foundation/Tomcat
> 6.0/webapps/examples/WEB-INF/classes/velocity.properties");
>
>              ve.init();
>
>              /*  next, get the Template  */
>
>              if(ve.templateExists(strtmp))
>
>              {
>
>                  str="Template found !!!!!";
>
>              }
>
>              else
>
>              {
>
>                  str="Template not  found !!!!!";
>
>              }
>
>              Template t = ve.getTemplate(strtmp );
>
>              /*  create a context and add data */
>
>              VelocityContext context = new VelocityContext();
>
>              context.put("name", "World");
>
>              /* now render the template into a StringWriter */
>
>
>
>              t.merge( context, writer );
>
>              /* show the World */
>
>             // System.out.println( writer.toString() );
>
>      }
>
>        catch (Exception e)
>
>          {
>
>            System.out.print("Error"+ e+"\n");
>
>          }
>
>
>
>
>
>
>
>
>
> If I have the same source code into a servelet, the servlet don't find
> the
>
> Template.
>
>
>
> Somebody knows where I can find a small example for this???
>
> I have found more solutions one different websites.
>
> I have tried more of this solutions and its not working.
>
>
>
> Thanks
>
>
>
> Stefan Mutschlechner
>

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@velocity.apache.org
For additional commands, e-mail: general-help@velocity.apache.org