Java, Software Development, Tomcat

Tomcat 7 by Dissection: How CGI File Upload Works

I wonder which old Tomcat version our application based its CGIServlet class on. CGI HTTP POST was not working, and recently another problem has cropped up – CGI File Upload does not work. What gives? I can only speculate.

  • The original codes may have been taken from a development branch,
  • Tomcat CGI was, by then, an afterthought, incomplete, and kept dormant as a module,
  • Or the functions were omitted in the early derivatives, early versions of our application.

Whatever. The fact of the matter is that there is a ticket assigned to me. So, how should the codes be modified to make the file upload work? The solution is to write out the bytes from the HttpServletRequest InputStream object onto the Process object’s OutputStream when the content length is more significant than zero. It figures, right?

In Tomcat 7, the functionality is coded in CGIServlet class as follows:

 Here is a sample CGI script to play around with TC7’s CGI File Upload function:

 TC7 Rev 1097024

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like