Apache Velocity - Template-Pfad

riseX

Mitglied
Hallo .. ich hab wieder mal nen Problem ...

ich bin zu dämlich.

Ich hab in einem Servlet eine VelocityEngine angelegt ... dann hab ich ein Template erstellt ... alles im gleichen Package ... und er findet die Template-Datei nicht ... kann mir einer da mal nen Wink geben, wo der Fehler liegt?

Code:
	VelocityEngine ve = new VelocityEngine();
	ve.init();

	/*  next, get the Template  */
	Template t = ve.getTemplate( "incl_dol.vm" );

	/*  create a context and add data */
	VelocityContext context = new VelocityContext();
							
	if (session.getAttribute("localeObject") != null) {
		ISM_DOL_SEND= ((ResourceBundle) session.getAttribute("localeObject")).getString("ISM_DOL_SEND");
	}

	context.put("ISM_DOL_SEND", ISM_DOL_SEND);
	context.put("ISM_DOL_CHOOSE", "test");

	/* now render the template into a StringWriter */
	StringWriter writer = new StringWriter();
	t.merge( context, writer );
	out.println( writer.toString());

Wie gesagt .. beides in EINEM Package
 
OK

ich hab mir schon geholfen:

Code:
       	Properties p = new Properties();
       	String path = getServletContext().getRealPath("/templates");
       	p.setProperty( "file.resource.loader.path", path );
				        	
	VelocityEngine ve = new VelocityEngine();
	ve.init(p);

	/*  next, get the Template  */
	Template t = ve.getTemplate( "incl_dol.vm" );

	/*  create a context and add data */
	VelocityContext context = new VelocityContext();
							
							
	if (session.getAttribute("localeObject") != null) {
		ISM_DOL_SEND= ((ResourceBundle) session.getAttribute("localeObject")).getString("ISM_DOL_SEND");
	}

	context.put("ISM_DOL_SEND", ISM_DOL_SEND);
	context.put("ISM_DOL_CHOOSE", "World");

	/* now render the template into a StringWriter */
	StringWriter writer = new StringWriter();
	t.merge( context, writer );
	out.println( writer.toString());
 

Neue Beiträge

Zurück