title: How is Velocity Template Engine used for View in Java Web Applications?
body: <p>When you have this sample code:</p>
  
  <pre><code>RequestDispatcher requestDispatcher =  request.getRequestDispatcher("index.jsp");
  requestDispatcher.forward(request, response);
  </code></pre>
  
  <p>and you have a simple <code>index.jsp</code> file, well Tomcat will figure out this is a jsp file and it will be <strong>translated</strong> into a Java class first, then compiled and then it will be executed.. This is all fine.</p>
  
  <p>Here, in this page: <a href="http://edwin.baculsoft.com/2011/06/beginning-apache-velocity-creating-a-simple-web-application/" rel="nofollow">http://edwin.baculsoft.com/2011/06/beginning-apache-velocity-creating-a-simple-web-application/</a> there is a simple example/tutorial showing how velocity template engine can be used for rendering view where velocity templating language is used.</p>
  
  <p>There is one thing I do not understand, in which step does the container (or the jvm?) know it should use the <strong>Velocity Template Engine</strong> to interpret the <strong><code>.vm</code></strong> file and do the processing on the file correctly? How does it know it is not a JSP file? Only by the extension as in JSP files? </p>
  
  <p>I am not asking how the request is forwarded to the <code>.vm</code> file. I am asking when and how Velocity Engine kicks in to create the HTML from the <code>.vm</code> file using the data object we provided in the request object. Why is the .vm file not being translated into a Java Class like a jsp file? How does Tomcat decide it is not the right thing to do to try translating into a <code>_jsp.class</code> file but rather uses Velocity Template Engine? </p>