velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Utt <brian_...@yahoo.com>
Subject Trouble Loading a Template from a WAR file - Velocity 1.4 - WLS 8.12
Date Tue, 15 Jun 2004 14:04:18 GMT
I am having trouble using the Velocity 1.4 package and
loading a template from a WAR file.  I can
successfully use the package with a command line java
application, but when I ported it into a servlet, I
get the infamous "Unable to find resource..." message.

I have tried to load the template with a generic
servlet as well as extending the VelocityServlet and I
seem to be missing an important step.  My .vm Template
files are in my deployed WAR file in the
WEB-INF/classes "folder" and I am running on Weblogic
8.12.

Below is my servlet code:

_____________________________________

public class DataDownloadServlet 
       extends VelocityServlet
{
  public Template handleRequest( 
         HttpServletRequest request, 
         HttpServletResponse response, 
         Context context ) 
  throws IOException, ServletException 
  {
    try
    {
      //get the pool number to extract the data for.
      String[] reqVals = 
        request.getParameterValues("pn");

      String uri = request.getRequestURI();

      List beans = 
        InternetDataManager.process(reqVals);

      Template template = null;
      String templateName = "";

      response.setContentType("application/vnd.xml");
      templateName = "PoolXML.vm";

      try
      {
          template = getTemplate(templateName);

          context.put("pools", beans);

          mergeTemplate(template, context, response);
      }
      catch( ResourceNotFoundException rnfe )
      {
        // couldn't find the template
        System.out.println("Template Not Found: " + 
                            templateName + 
                            ": " + rnfe.getMessage());
        throw new ServletException(rnfe);
      }
      catch( ParseErrorException pee )
      {
        // syntax error : problem parsing the template
        System.out.println("Prob Parsing template "+
                            templateName + 
                            ": " +pee.getMessage());
        throw new ServletException(pee);
      }
      catch( Exception e )
      {
        System.out.println("Weird Problem: " + 
                            e.getMessage());
        throw new ServletException(e);
      }
    }
    catch (Exception ex)
    {
      System.out.println("Caughted exception: " + 
                          ex.getMessage());
      ex.printStackTrace(System.out);

      throw new ServletException(ex);
    }
    return null;
  }
}

_____________________________________


I have read about a velocity.properties file, but I
have not used one on my command line app and I was
hoping not to have to use one on the j2ee app, but I
might very well be wrong about that.  Any assistance
will be very much appreciated!

Thanks in advance!

-Brian



=====
Debugging is twice as hard as writing the code in the first place. Therefore, if you write
the code as cleverly as possible, you are, by definition, not smart enough to debug it. --Kernighan

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


Mime
View raw message