You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2001/02/26 05:51:55 UTC

cvs commit: jakarta-velocity/examples/servlet_example1 SampleServlet.java

geirm       01/02/25 20:51:55

  Modified:    examples/servlet_example1 SampleServlet.java
  Log:
  Showed how to catch the new exceptions o.a.v.exception.*
  
  Revision  Changes    Path
  1.2       +29 -7     jakarta-velocity/examples/servlet_example1/SampleServlet.java
  
  Index: SampleServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/examples/servlet_example1/SampleServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SampleServlet.java	2001/02/12 03:11:55	1.1
  +++ SampleServlet.java	2001/02/26 04:51:54	1.2
  @@ -64,35 +64,57 @@
   import org.apache.velocity.servlet.*;
   import org.apache.velocity.runtime.*;
   
  +import org.apache.velocity.exception.ResourceNotFoundException;
  +import org.apache.velocity.exception.ParseErrorException;
  +
   /**
    * Sample of how to use the VelocityServlet.
    * This example shows how to add objects to the context and
    * pass them to the template.
    * 
    * @author Dave Bryson
  - * $Revision: 1.1 $
  + * $Revision: 1.2 $
    */
   public class SampleServlet extends VelocityServlet
   {
       public Template handleRequest( Context ctx )
  -    {
  -        Template outty = null;
  -        
  +    {        
  +        /*
  +         *  set up some data to put into the context
  +         */
  +
           String p1 = "Bob";
           String p2 = "Harold";
           
           Vector personList = new Vector();
           personList.addElement( p1 );
           personList.addElement( p2 );
  +
  +        /*
  +         *  Add the list to the context.
  +         *  This is how it's passed to the template.
  +         */
   
  -        // Add the list to the context
  -        // this is how it's passed to the template
           ctx.put("theList", personList );
           
  +        /*
  +         *  get the template.  There are three possible
  +         *  exceptions.  Good to know what happened.
  +         */
  +
  +        Template outty = null;
  +        
           try
           {
  -            // Get the template
               outty =  getTemplate("sample.vm");
  +        }
  +        catch( ParseErrorException pee )
  +        {
  +            System.out.println("SampleServlet : parse error for template " + pee);
  +        }
  +        catch( ResourceNotFoundException rnfe )
  +        {
  +            System.out.println("SampleServlet : template not found " + rnfe);
           }
           catch( Exception e )
           {