You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rhino <rh...@sympatico.ca> on 2003/05/08 15:24:26 UTC

Need help with upload servlet

I am trying to develop a servlet that does some file uploads via a form but it isn't working. Can someone either help me figure out what is wrong -OR- point me to a good example of code that does a file upload, ideally without using a third party package?

Rather than re-inventing the wheel, I thought I'd look around for an existing example and then adapt it as necessary. I found a promising candidate at http://www.thebook-demo.com/java-server/servlets/index.html. It appears to be an earlier version of the examples page from Tomcat and has one example called "File Upload". I clicked on "Source" and created a servlet out of these components, then created a web.xml to tie it all together.

When I do http://localhost:8080/UploadServlet/text.html, I get the input form just fine. I decided to concentrate on the MultipartParser Upload Servlet first. I filled in a name on the "What is your name?" line, then choose a file via the Browse button beside the first of the "Which file to upload?" text fields, then clicked on the Submit button. I got this from Tomcat:

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
	at java.lang.Thread.run(Thread.java:536)

root cause 

java.lang.NoClassDefFoundError: javax/servlet/ServletRequest
	at upload.DemoParserUploadServlet.doPost(DemoParserUploadServlet.java:51)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
	at java.lang.Thread.run(Thread.java:536)


--------------------------------------------------------------------------------

Apache Tomcat/4.1.24

The only code in the stacktrace that comes directly from the downloaded code is the first line of the "root cause" stacktrace, which refers to upload.DemoParserUploadServlet.doPost line 51, which is the first line inside the try block of the doPost. This is the line:

MultipartParser mp = new MultipartParser(request, 10*1024*1024); // 10MB


It appears to be me that it can't find the MultiPartParser class but that doesn't make a lot of sense because it doesn't actually say that anywhere *and* the code compiled fine when I put the cos.jar file in the project's main directory. Or do I need to modify server.xml or one of the other configuration files so that Tomcat can see the cos.jar file?

I am using Tomcat 4.1.24, Eclipse 2.1 (RC1), Sysdeo V2.1, and Windows XP Pro.


Rhino
---
rhino1 AT sympatico DOT ca
"If you want the best seat in the house, you'll have to move the cat."

Re: Need help with upload servlet

Posted by Rhino <rh...@sympatico.ca>.
Thanks for the suggestion! I'll look into it.

Rhino

----- Original Message ----- 
From: "Erik Price" <ep...@ptc.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Thursday, May 08, 2003 9:32 AM
Subject: Re: Need help with upload servlet


>
>
> Rhino wrote:
> > I am trying to develop a servlet that does some file uploads via a form
> > but it isn't working. Can someone either help me figure out what is
> > wrong -OR- point me to a good example of code that does a file upload,
> > ideally without using a third party package?
> >
> > Rather than re-inventing the wheel, I thought I'd look around for an
> > existing example and then adapt it as necessary.
>
> You can always try
> <http://jakarta.apache.org/commons/fileupload/index.html> ?
>
>
>
> Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


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


Re: Need help with upload servlet

Posted by Erik Price <ep...@ptc.com>.

Rhino wrote:
> I am trying to develop a servlet that does some file uploads via a form 
> but it isn't working. Can someone either help me figure out what is 
> wrong -OR- point me to a good example of code that does a file upload, 
> ideally without using a third party package?
>  
> Rather than re-inventing the wheel, I thought I'd look around for an 
> existing example and then adapt it as necessary.

You can always try
<http://jakarta.apache.org/commons/fileupload/index.html> ?



Erik


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


Re: Need help with upload servlet

Posted by Rhino <rh...@sympatico.ca>.
I tried putting cos.jar in the WEB-INF/lib directory. I refreshed my
context, stopped and restarted Tomcat, and tried the servlet again. Same
error.

Then I tried adding cos.jar to the Tomcat common/lib directory *as well*.
Again, I refreshed my context, stopped and restarted Tomcat, and tried the
servlet again. Same error.

How could it be failing to find MultiPartParser class under these
circumstances and why isn't that class mentioned in the stacktrace if it is
the problem? Is it possible that something else is missing or in the wrong
place?

Could my web.xml be wrong? Here it is:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<servlet>

<servlet-name>parserupload</servlet-name>

<servlet-class>upload.DemoParserUploadServlet</servlet-class>

<init-param>

<param-name>uploadDir</param-name>

<param-value>/uploads</param-value>

</init-param>

</servlet>

<servlet>

<servlet-name>requestupload</servlet-name>

<servlet-class>upload.DemoRequestUploadServlet</servlet-class>

<init-param>

<param-name>uploadDir</param-name>

<param-value>/uploads</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>parserupload</servlet-name>

<url-pattern>/parserupload</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>requestupload</servlet-name>

<url-pattern>/requestupload</url-pattern>

</servlet-mapping>

</web-app>


Rhino

----- Original Message ----- 
From: "Tom Lyle" <to...@limehouse.co.uk>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Thursday, May 08, 2003 9:36 AM
Subject: RE: Need help with upload servlet


> Not sure what you mean by this:
> >the code compiled fine when I put the cos.jar file in the project's main
> directory
>
> for Tomcat to pick up the cos.jar it needs to be in your webapps
WEB-INF/lib
> directory or in the Tomcat common/lib directory
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


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


RE: Need help with upload servlet

Posted by Tom Lyle <to...@limehouse.co.uk>.
Not sure what you mean by this:
>the code compiled fine when I put the cos.jar file in the project's main
directory

for Tomcat to pick up the cos.jar it needs to be in your webapps WEB-INF/lib
directory or in the Tomcat common/lib directory

Tom


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