• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Velocity Templates with Servlets

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, im trying to use velocity templates within a servlet get method.
i keep getting the error: Resource not Found for the ".vm" template file.
Below is the code i've used:

VelocityEngine ve = new VelocityEngine();
Properties props = new Properties();
String path = getServletContext().getRealPath("/");
props.setProperty( "resource.loader", "class" );
props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path+"WEB-INF" );

out.println(props.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH));

Velocity.init(props);
VelocityContext context = new VelocityContext();
context.put("username", "administrator");
context.put("password","abc");
Template template = null;

template = Velocity.getTemplate("documentum-config.vm");
/*render the template into a Writer, here a StringWriter */

StringWriter writer = new StringWriter();
template.merge( context, writer );

File file=new File("/WEB-INF/documentum-config.xml");
FileOutputStream fos=new FileOutputStream(file);
DataOutputStream dos=new DataOutputStream(fos);
dos.write(writer.toString().getBytes());
dos.close();
}


Any pointers are welcome !
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic