I forgot to mention that I added this code to your bean :) try{ setOutput("Demo Parser Upload Bean"); MultipartParser mp = new MultipartParser(req, 10*1024*1024); Part part; while ((part = mp.readNextPart()) != null) { String name = part.getName(); if (part.isParam()) { // it's a parameter part so do nothing } else if (part.isFile()) { // it's a file part FilePart filePart = (FilePart) part;
if (getFileName()!= null) { // the part actually contained a file File filepath=new File("c:/Temp/rajiv.xml"); long size = filePart.writeTo(filepath); setFileName(filePart.getFileName()); } else { //file was empty add error code here } } } }catch(Exception e){ e.printStackTrace(); } you have to specify the directory or file to which you want to upload. -----Original Message----- From: Rajiv Ramanasankaran [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 10, 2002 2:50 PM To: Tomcat Users List Subject: RE: Error with multipartParser Its is working fine for me!! The file is getting uploaded and I don't get an error at all..What version of Tomcat are you using??? I am using Tomcat 3.2 . There might be an incompatibility problem. Rajiv -----Original Message----- From: Sam Seaver [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 10, 2002 2:11 PM To: [EMAIL PROTECTED] Subject: RE: Error with multipartParser OK, here's the JSP page I'm using, note it reloads itself once POST is pressed, and then activates the bean: <html> <head> <title>file upload</title> </head> <body bgcolor="#c8d8f8"> <form action="jguru.jsp" enctype="multipart/form-data" method=post> <center> <table cellpadding=4 cellspacing=2 border=0> <th bgcolor="#CCCCFF" colspan=2> <font size=5>User Registration</font> </th> <tr> <td valign=top colspan=2> <b>Which XML file would you like to upload?</b> <br /> <input type="file" name="fileName" /> <br></td> </tr> <tr> <td align=center colspan=2> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </td> </tr> </table> </center> </form> <%-- Create the bean only when the form is posted --%> <% if (request.getMethod().equals("POST")) { %> <jsp:useBean id="xmlHandler" class="com.jguru.SimpleBean"> <jsp:setProperty name="xmlHandler" property="fileName" /> </jsp:useBean> <p> <hr> <font color=red> <br><b>File to upload:</b><br> <jsp:getProperty name="xmlHandler" property="fileName" /> <br> <% xmlHandler.doPost(request, response); %> <br/><b>Bean Output:</b><br/> <jsp:getProperty name="xmlHandler" property="output" /> <% } %> </font> </body> </html> then there's the bean itself: package com.jguru; import java.io.*; import java.util.*; import javax.servlet.http.*; import javax.servlet.*; import com.oreilly.servlet.*; import com.oreilly.servlet.multipart.*; public class SimpleBean extends HttpServlet { private String fileName; private String name; private String type; private String output; public SimpleBean(){ fileName=""; name=""; type=""; output=""; } public void setFileName(String x){ fileName=x; } public void setName(String x){ name=x; } public void setType(String x){ type=x; } public void setOutput(String x){ output=x; } public void appendOutput(String x){ output=output+x; } public String getFileName(){ return fileName; } public String getName(){ return name; } public String getType(){ return type; } public String getOutput(){ return output; } public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ try{ setOutput("Demo Parser Upload Bean"); MultipartParser mp = new MultipartParser(req, 10*1024*1024); }catch(Exception e){ e.printStackTrace(): } } } the log gave very little, what i cut and pasted was from the log, but with the stacktrace this is what it did: 2002-10-10 14:09:29 StandardContext[/sam]: Mapping contextPath='/sam' with requestURI='/sam/jguru.jsp' and relativeURI='/jguru.jsp' 2002-10-10 14:09:29 StandardContext[/sam]: Trying exact match 2002-10-10 14:09:29 StandardContext[/sam]: Trying prefix match 2002-10-10 14:09:29 StandardContext[/sam]: Trying extension match 2002-10-10 14:09:29 StandardContext[/sam]: Mapped to servlet 'jsp' with servlet path '/jguru.jsp' and path info 'null' and update=true 2002-10-10 14:09:33 StandardContext[/sam]: Mapping contextPath='/sam' with requestURI='/sam/jguru.jsp' and relativeURI='/jguru.jsp' 2002-10-10 14:09:33 StandardContext[/sam]: Trying exact match 2002-10-10 14:09:33 StandardContext[/sam]: Trying prefix match 2002-10-10 14:09:33 StandardContext[/sam]: Trying extension match 2002-10-10 14:09:33 StandardContext[/sam]: Mapped to servlet 'jsp' with servlet path '/jguru.jsp' and path info 'null' and update=true 2002-10-10 14:09:33 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: com/oreilly/servlet/multipart/MultipartParser at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2 48) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja va:260) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(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.ja va:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(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:2396) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180 ) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve. java:170) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172 ) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(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.invok eNext(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:405) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne ction(Http11Protocol.java:380) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav a:533) at java.lang.Thread.run(Thread.java:536) ----- Root Cause ----- javax.servlet.ServletException: com/oreilly/servlet/multipart/MultipartParser at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp l.java:497) at org.apache.jsp.jguru_jsp._jspService(jguru_jsp.java:128) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2 04) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja va:260) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(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.ja va:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(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:2396) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180 ) : at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve. java:170) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172 ) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok eNext(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.invok eNext(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:405) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne ction(Http11Protocol.java:380) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav a:533) at java.lang.Thread.run(Thread.java:536) >From: "Rajiv Ramanasankaran" <[EMAIL PROTECTED]> >Reply-To: "Tomcat Users List" <[EMAIL PROTECTED]> >To: "Tomcat Users List" <[EMAIL PROTECTED]> >Subject: RE: Error with multipartParser >Date: Wed, 9 Oct 2002 23:03:24 -0500 > >Can you give the full exception stacktrace?? That might help us figure it >out. try e.printStackTrace() instead of creating the printwrite and >printing >to standard error. Send the tomcat log files too. >Rajiv > > > -----Original Message----- > > From: Sam Seaver [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, October 09, 2002 2:09 PM > > To: [EMAIL PROTECTED] > > Subject: Error with multipartParser > > > > > > I cannot work this out as I get no more in my error messages > > despite trying > > to use the usual ways of debugging the bean. Basically I'm using a bean > > that extends HttpServlet and uses Hunter's MultipartParser, and the >error > > ALWAYS occurs when I try to create an instance of the parser... > > > > Error: > > > > root cause > > > > javax.servlet.ServletException: > > com/oreilly/servlet/multipart/MultipartParser > > at > > org.apache.jasper.runtime.PageContextImpl.handlePageException(Page > > ContextImpl.java:497) > > > > Code: > > > > import java.io.*; > > import java.util.*; > > import javax.servlet.http.*; > > import javax.servlet.*; > > > > import com.oreilly.servlet.*; > > import com.oreilly.servlet.multipart.*; > > > > public class SimpleBean extends HttpServlet { > > > > private String fileName; > > private String name; > > private String type; > > private String output; > > > > public SimpleBean(){ > > fileName=""; > > name=""; > > type=""; > > output=""; > > } > > > > public void setFileName(String x){ > > fileName=x; > > } > > > > public void setName(String x){ > > name=x; > > } > > > > public void setType(String x){ > > type=x; > > } > > > > public void setOutput(String x){ > > output=x; > > } > > > > public void appendOutput(String x){ > > output=output+x; > > } > > > > public String getFileName(){ > > return fileName; > > } > > > > public String getName(){ > > return name; > > } > > > > public String getType(){ > > return type; > > } > > > > public String getOutput(){ > > return output; > > } > > > > public void doPost(HttpServletRequest req, HttpServletResponse res) > > throws ServletException, IOException{ > > setOutput("Demo Parser Upload Bean"); > > res.setContentType("text/html"); > > ServletOutputStream out = res.getOutputStream(); > > > > try{ > > MultipartParser mpParser = new MultipartParser(req, > > 10*1024*1024); > > }catch (Exception e){ > > StringWriter sw = new StringWriter(); > > PrintWriter pw = new PrintWriter(sw); > > e.printStackTrace(pw); > > > > } > > > > > > > > } > > } > > > > > > > > "JC Rules" > > > > _________________________________________________________________ > > Chat with friends online, try MSN Messenger: http://messenger.msn.com > > > > > > -- > > To unsubscribe, e-mail: ><mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: ><mailto:[EMAIL PROTECTED]> > > > >-- >To unsubscribe, e-mail: ><mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: ><mailto:[EMAIL PROTECTED]> > > > > >-- >To unsubscribe, e-mail: ><mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: ><mailto:[EMAIL PROTECTED]> "JC Rules" _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>