velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shawn Church" <>
Subject Re: Form upload failure
Date Tue, 02 Jul 2002 18:57:15 GMT

> That "HTTP/1.1 200 OK" status code means that the request has succeeded.


> Can you clarify "If my servlet returns a different template than the
> > one which made the request, everything is fine." for me?

My servlet (upload) always returns getTemplate("upload.vm"), and the
template's <form action is always the upload class.  This would be a normal
situation where, for example, you need to validate form input prior to
processing, and in the case of an invalid input the servlet will request the
same template to be presented again.

> It seems that you are uploading a file (which is working, file on server
> now?) and then merging a template called "upload.vm" to return back to the
> browser? I assume this template just contains the <form> that allows
> of another file? Are you saying that if you use any other template in
> getTemplate(name) that it returns to the browser?

The code I'm testing with is not concerned with the actual file upload, but
rather is just attempting to isolate a problem which occurs prior to the
upload code being invoked.  In my real code, the actual upload works fine,
but only if I don't return the same (requesting) template back to Velocity.
I've stripped everything non-essential, so I only have a single servlet and
a single template.

It would be interesting to know if you experience the same problem by
implementing nothing more than this single template and the servlet below.
When you see the default "Browse" button on your browser page, select a file
to upload, then click Submit.  This is where the exception occurs (the fact
that no code exists to actually process the file upload request is not
relevant to reproduce the problem).

I provided the complete template earlier, and here's the complete servlet
(per Nick's request, I added the System.err.println(e.toString()); to the
catch code, but it doesn't produce any exceptions):

package com.gc.ecr;

import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.servlet.VelocityServlet;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.ParseErrorException;

public class upload extends VelocityServlet
 public Template handleRequest( HttpServletRequest _req, HttpServletResponse
_res, Context _context)
  String templateName = "upload.vm";

  // return the appropriate template
   return getTemplate(templateName);
    catch (Exception e)

  return null;

 *  A fancier version of loadConfiguration(), this will
 *  set the log file to be off of the webapp root, and
 *  will do the same with the file loader paths
 protected Properties loadConfiguration(ServletConfig config )
   throws IOException, FileNotFoundException
    *  get our properties file and load it

  String propsFile = config.getInitParameter(INIT_PROPS_KEY);
  Properties p = new Properties();

  if ( propsFile != null )
     String realPath = getServletContext().getRealPath(propsFile);

     if ( realPath != null )
         propsFile = realPath;

     p.load( new FileInputStream(propsFile) );

  *  first, normalize our velocity log file to be in the
  *  webapp

  String log = p.getProperty( Velocity.RUNTIME_LOG);

  if (log != null )
     log = getServletContext().getRealPath( log );

     if (log != null)
         p.setProperty( Velocity.RUNTIME_LOG, log );

  *  now, if there is a file loader resource path, treat it the
  *  same way.

  String path = p.getProperty( Velocity.FILE_RESOURCE_LOADER_PATH );

  if ( path != null)
     path = getServletContext().getRealPath(  path );

     if ( path != null)
         p.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH, path );

  return p;

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message