Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Velocity 1.5b2 & VelocityView

Reply
Thread Tools

Velocity 1.5b2 & VelocityView

 
 
Xabi
Guest
Posts: n/a
 
      12-28-2006
First of all I'd like to say hello everyone, since I'm new to the
group. Now to the "meat".

I'm a newcommer to the velocity templating system and I'm having some
trouble. I've setup Tomcat 5.5.2 and compiled Velocity 1.5 beta 2 and
VelocityTools 1.2. I've created a servlet that extends
VelocityViewServlet:

public class index extends VelocityViewServlet
{

public Template handleRequest(HttpServletRequest request,
HttpServletResponse response, Context context)
throws ParseErrorException, ResourceNotFoundException
{
Template tpl = null;
context.put("name","Xabi");
try
{
tpl = super.getTemplate ("test.vm");

StringWriter writer = new StringWriter();
tpl.merge (context,writer);
}
catch (ResourceNotFoundException rnfd)
{
System.out.println ("<p>Error: No se encontró la
plantilla</p>");
rnfd.printStackTrace (System.out);
}
catch (ParseErrorException perrex)
{
System.out.println ("<p>Error: Fallo parseando la
plantilla</p>");
perrex.printStackTrace (System.out);
}
catch (Exception ex){}
return tpl;
}

I've also added the corresponding servlet mappings in my web.xml:

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet-name>index</servlet-name>
<servlet-class>index</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>velocity</servlet-name>

<servlet-class>org.apache.velocity.tools.view.servlet.Veloc ityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
<init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>

And also created a velocity.properties file in
/WEB-INF/velocity.properties:

resource.loader = webapp
webapp.resource.loader.class =
org.apache.velocity.tools.view.servlet.WebappLoade r
webapp.resource.loader.path=/templates
webapp.resource.loader.cache = true
runtime.log=/WEB-INF/logs/velocity.log
input.encoding=UTF-8
output.encoding=UTF-8

And created a very simple template called test.vm in
/MyAppRoot/templates/test.vm:

<?xhtml version="1.0" encoding="UTF-8"?>
<html>
<head>
<title>Test</title>
</head>
<body>
THIS IS A TEST:</br>
Hello $name
</body>
</html>

But whenever I go to http://localhost:8080/myapp , I only get a blank
page.
Digging into Tomcat logs, I've found this:

INFO: Velocity :
************************************************** *****************
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Starting Apache Velocity v1.5-beta2 (compiled:
2006-11-24 22:45:47)
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity : RuntimeInstance initializing.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Default Properties File:
org\apache\velocity\runtime\defaults\velocity.prop erties
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Trying to use logger class
org.apache.velocity.tools.view.servlet.ServletLogg er
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [info] LogSystem has been deprecated. Please use a
LogChute implementation.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Default ResourceManager initializing. (class
org.apache.velocity.runtime.resource.ResourceManag erImpl)
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] ResourceLoader instantiated:
org.apache.velocity.tools.view.servlet.WebappLoade r
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [info] WebappLoader : initialization starting.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [info] WebappLoader : added template path -
'/templates/'
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [info] WebappLoader : initialization complete.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] ResourceCache: initialized (class
org.apache.velocity.runtime.resource.ResourceCache Impl)
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity : Default ResourceManager initialization complete.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Loaded System Directive:
org.apache.velocity.runtime.directive.Literal
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Loaded System Directive:
org.apache.velocity.runtime.directive.Macro
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Loaded System Directive:
org.apache.velocity.runtime.directive.Parse
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Loaded System Directive:
org.apache.velocity.runtime.directive.Include
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Loaded System Directive:
org.apache.velocity.runtime.directive.Foreach
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Created '20' parsers.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity : Velocimacro : initialization starting.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Velocimacro : "velocimacro.library" is not
set. Trying default library: VM_global_library.vm
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Velocimacro : Default library not found.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Velocimacro : allowInline = true : VMs can be
defined inline in templates
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Velocimacro : allowInlineToOverride = false :
VMs defined inline may NOT replace previous VM definitions
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Velocimacro : allowInlineLocal = false : VMs
defined inline will be global in scope if allowed.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [debug] Velocimacro : autoload off : VM system will
not automatically reload global library macros
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity : Velocimacro : Velocimacro : initialization complete.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity : RuntimeInstance successfully initialized.
28-dic-2006 19:00:48 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [info] VelocityViewServlet: Default content-type is:
text/html; charset=UTF-8
28-dic-2006 19:00:52 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [error] ResourceManager : unable to find resource
'test.vm' in any resource loader.
28-dic-2006 19:00:52 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [warn] VelocityViewServlet: couldn't find template to
match request.
28-dic-2006 19:00:53 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [error] ResourceManager : unable to find resource
'test.vm' in any resource loader.
28-dic-2006 19:00:53 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [warn] VelocityViewServlet: couldn't find template to
match request.
28-dic-2006 19:00:53 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [error] ResourceManager : unable to find resource
'test.vm' in any resource loader.
28-dic-2006 19:00:53 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [warn] VelocityViewServlet: couldn't find template to
match request.
28-dic-2006 19:00:53 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [error] ResourceManager : unable to find resource
'test.vm' in any resource loader.
28-dic-2006 19:00:53 org.apache.catalina.core.ApplicationContext log
INFO: Velocity [warn] VelocityViewServlet: couldn't find template to
match request.


Witch for me indicates that the templates path I setup in
resource.loader is readed correctly but for some reason I don't know
whenever I return the template, it's searched in the AppRoot folder.

Does anybody have an idea on how to fix this?

P.S: Sorry about the long post, but I thought giving more information
would be better.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.io.FileNotFoundException: velocity.log (Too many open files) when i use velocity to send emails bond Java 1 06-28-2007 04:00 AM
velocity user ..guide me for validation of velocity macro tags.... HemantS Java 0 06-12-2007 04:04 AM
Happy New Years to Everyone at Velocity Reviews! bigal The Lounge 71 02-08-2006 09:39 AM
Official 2005 Velocity Reviews Screensaver unholy The Lounge 47 11-15-2005 09:39 PM
Time for the official 2005 Velocity Reviews Screen Saver!!!! bigal Case Modding 65 11-02-2005 07:16 AM



Advertisments