commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Schalk" <sch...@volume4.co.za>
Subject Re: [FileUpload] basic question
Date Thu, 13 Feb 2003 22:21:32 GMT
Derek

You should post a bug report on this in the struts reporting.

Kind Regards »
Schalk Neethling »
Volume4.Development.Multimedia.Branding
.emotionalize.conceptualize.visualize.realize
Tel: +27125468436
Fax: +27125468436
email: schalk@volume4.co.za
url: www.volume4.co.za
----- Original Message -----
From: "Derek A. Bodin" <bodinda@uwec.edu>
To: "'Jakarta Commons Users List'" <commons-user@jakarta.apache.org>
Sent: Friday, February 14, 2003 12:15 AM
Subject: RE: [FileUpload] basic question


> Thanks for the help.  I figured out it was because I was using struts
> and the request input stream had already been exhausted.  There should
> be a warning about that.
>
> -Derek
>
>
> -----Original Message-----
> From: Schalk [mailto:schalk@volume4.co.za]
> Sent: Thursday, February 13, 2003 3:49 PM
> To: Jakarta Commons Users List
> Subject: Re: [FileUpload] basic question
>
> Derek
>
> Below is the code:
> /**
>  * uploadFile.java
>  *
>  * Created on December 11, 2002, 11:40 PM
>  *
>  *
>  * @author  Design_DEMON
>  * @version 1.0
>  * Based on base classes from org.apache.commons.fileupload
>  * Explenation of Strings:<br>
>  * public String folder:: This string contains the information of your
> local
>  * directory for testing your application locally.
>  * <br>
>  * public String tempFolder:: This is the location of your temp folder
> when
>  * testing the application locally.
>  * <br>
>  * public String serverFolder:: Uncomment this line when transfering the
> files
>  * to the server. This is the complete string from the server root.
>  * <br>
>  * public String serverTemp:: Uncomment this line when transfering to
> the
> server.
>  * Tis should point to your temp directory on the server from the server
> root.
>  */
>
> package volume4.sharelite.fileManager;
>
> import java.io.*;
> import java.util.*;
> import java.lang.*;
> import org.apache.commons.fileupload.*;
> import java.net.*;
> import java.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
>
> public class uploadFile extends HttpServlet {
>     public String folder = "/Program Files/Apache Tomcat
> 4.0/webapps/PersonnelFinance/fileShare/fileExchange/files/";
>     public String temp = "/temp";
>     //public String serverFolder =
> "/var/www/vhosts/personnelfinance/webapps/Persfin/fileShare/fileExchange
> /fil
> es/";
>     //public String serverTemp =
> "/var/www/vhosts/personnelfinance/webapps/Persfin/temp/";
>     public String DRIVER, URL, USER, PASS, recipient, fieldName,
> fieldData,
> fileName, fileFieldName, comment, filePath;
>
>
>     public void init() throws ServletException {
>     ServletContext context = getServletContext();
>     DRIVER = context.getInitParameter("DRIVER");
>     URL = context.getInitParameter("PFURL");
>     USER = context.getInitParameter("PFUSER");
>     PASS = context.getInitParameter("PFPASS");
>     }
>
>     protected void processRequest(HttpServletRequest req,
> HttpServletResponse res)
>     throws ServletException, java.io.IOException {
>
>         res.setContentType("text/html");
>         PrintWriter out = res.getWriter();
>         Connection con = null;
>
>         try {
>
>             FileUpload upload = new FileUpload();
>
>             upload.setSizeMax(400000000);
>             upload.setSizeThreshold(4096);
>             upload.setRepositoryPath(temp);
>
>             List items = upload.parseRequest(req);
>
>             Iterator iter = items.iterator();
>             while (iter.hasNext()) {
>             FileItem item = (FileItem) iter.next();
>
>             if (item.isFormField()) {
>
>                 fieldName = item.getFieldName();
>
>                 if(fieldName.equals("recipient")) {
>                 fieldData = item.getString();
>                 recipient = fieldData;
>                 }
>                 else if(fieldName.equals("comment")) {
>                 fieldName = item.getFieldName();
>                 fieldData = item.getString();
>                 comment = fieldData;
>                 }
>                 System.out.println("recipient: ");
>                 System.out.println(recipient);
>                 System.out.println("comment: ");
>                 System.out.println(comment);
>
>
>             } else {
>
>                 if(item.getName().equals("")) {
>                     System.out.println("forwarding");
>                 } else {
>
>
>             fileName = item.getName();
>             fileFieldName = item.getFieldName();
>
>             StringTokenizer tokenizer = new StringTokenizer(fileName,
> "\\,
> :, /");
>             int amount = tokenizer.countTokens();
>             for (int i = 0; i < amount -1; i++) {
>                 tokenizer.nextToken();
>             }
>             String currentFile = tokenizer.nextToken();
>             filePath = folder + currentFile;
>
>             item.getInputStream();
>             item.write(folder + currentFile);
>
>             item.delete();
>
>             Class.forName(DRIVER);
>             con = DriverManager.getConnection(URL,USER,PASS);
>             PreparedStatement stmt = con.prepareStatement
>             ("INSERT INTO fileexchange (fileName, fileURI, comments,
> toUser)
> " +
>             "VALUES (?, ?, ?, ?)"
>             );
>
>             stmt.setString(1, currentFile);
>             stmt.setString(2, filePath);
>             stmt.setString(3, comment);
>             stmt.setString(4, recipient);
>
>             int result = stmt.executeUpdate();
>                 }
>
>         }
>     }
> res.sendRedirect("file_uploaded.jsp");
>
>         }   catch(FileUploadException fue) {
>          fue.printStackTrace();
>          out.println("There was and error when reading and writing the
> file
> to the server.");
>
>         } catch(Exception e) {
>             e.printStackTrace();
>         }
> }
>
>     protected void doGet(HttpServletRequest req, HttpServletResponse
> res)
>     throws ServletException, java.io.IOException {
>         processRequest(req, res);
>     }
>
>     protected void doPost(HttpServletRequest req, HttpServletResponse
> res)
>     throws ServletException, java.io.IOException {
>         processRequest(req, res);
>     }
> }
>
> Kind Regards >
> Schalk Neethling >
> Volume4.Development.Multimedia.Branding
> .emotionalize.conceptualize.visualize.realize
> Tel: +27125468436
> Fax: +27125468436
> email: schalk@volume4.co.za
> url: www.volume4.co.za
> ----- Original Message -----
> From: "Durham David Cntr 805CSS/SCBE" <David.Durham1@scott.af.mil>
> To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
> Sent: Thursday, February 13, 2003 11:42 PM
> Subject: RE: [FileUpload] basic question
>
>
> > Why not just post it in the email's text, I'm interested in this as
> well.
> >
> > > -----Original Message-----
> > > From: Schalk [mailto:schalk@volume4.co.za]
> > > Sent: Thursday, February 13, 2003 3:41 PM
> > > To: Jakarta Commons Users List
> > > Subject: Re: [FileUpload] basic question
> > >
> > >
> > > Derek
> > >
> > > Give me your email and I will send it there
> > >
> > >
> > > Kind Regards >
> > > Schalk Neethling >
> > > Volume4.Development.Multimedia.Branding
> > > .emotionalize.conceptualize.visualize.realize
> > > Tel: +27125468436
> > > Fax: +27125468436
> > > email: schalk@volume4.co.za
> > > url: www.volume4.co.za
> > > ----- Original Message -----
> > > From: "Derek A. Bodin" <bodinda@uwec.edu>
> > > To: "'Jakarta Commons Users List'" <commons-user@jakarta.apache.org>
> > > Sent: Thursday, February 13, 2003 11:37 PM
> > > Subject: RE: [FileUpload] basic question
> > >
> > >
> > > > The file didn't make it through, thanks for the quick response.
> > > >
> > > > -Derek
> > > >
> > > > -----Original Message-----
> > > > From: Schalk [mailto:schalk@volume4.co.za]
> > > > Sent: Thursday, February 13, 2003 3:34 PM
> > > > To: Jakarta Commons Users List
> > > > Subject: Re: [FileUpload] basic question
> > > >
> > > > Derek
> > > >
> > > > Try using the attached java file.
> > > >
> > > > Kind Regards >
> > > > Schalk Neethling >
> > > > Volume4.Development.Multimedia.Branding
> > > > .emotionalize.conceptualize.visualize.realize
> > > > Tel: +27125468436
> > > > Fax: +27125468436
> > > > email: schalk@volume4.co.za
> > > > url: www.volume4.co.za
> > > > ----- Original Message -----
> > > > From: "Derek A. Bodin" <bodinda@uwec.edu>
> > > > To: <commons-user@jakarta.apache.org>
> > > > Sent: Thursday, February 13, 2003 11:16 PM
> > > > Subject: [FileUpload] basic question
> > > >
> > > >
> > > > > Hi, I am using FileUpload with Tomcat 4.1.18.  I am
> > > sending my request
> > > > > with all of the correct fields, method=post,
> > > > > enctype="multipart/form-data".  FileUpload parses the request
> fine
> > > > > (without throwing an exception) but returns an empty
> > > list.  Is there
> > > > > something I am missing?  I read the API's and am modeling
> > > my test on
> > > > the
> > > > > example shown in the package description.  Any help would be
> > > > > appreciated.
> > > > >
> > > > > Thank You,
> > > > >
> > > > > -Derek
> > > > >
> > > > >
> > > > >
> > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > commons-user-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail:
> > > commons-user-help@jakarta.apache.org
> > > > >
> > > >
> > > >
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > commons-user-help@jakarta.apache.org
> > > >
> > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>



Mime
View raw message