commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schalk Neethling <sch...@volume4.com>
Subject Re: [FileUpload] It's works under Firefox but not on IE, why ?
Date Thu, 07 Jul 2005 11:48:52 GMT
Greetings

This should help you get started:

if(item.getFieldName().equals("uploadPDF")) {
               
                int i = item.getName().lastIndexOf('\\');
                uploadPDF = 
servletUtilities.filter(item.getName().substring(i+1));
                File savedFile = new File(serverFolder, 
servletUtilities.filter(item.getName().substring(i+1)) );
                item.write(savedFile);

Maxime wrote:

> Hello Mihael,
> Thank you veru much for your answer and the advice about Debian.
> Now I did some checking like : out.println(fileName);
> and it's returning all the path of the file under IE.
>
> out.println(fileName);
>
> IE  :             D:\DOCUMENTS\photo.jpg
> FireFox :     photo.jpg
>
> It's look like the problem is coming from here because for writing a 
> file I use that :
>
> String fileName = item.getName();
> File uploadedFile = new File(yourTempDirectory + fileName);
> item.write(uploadedFile);
>
> Well well, I wonder how I have to do in order to have the same result 
> as FireFox.
> Any idea ?
> Thank you very much anyway.
>
> Maxime
>
>
> ----- Original Message ----- From: "Knezevic, Mihael" 
> <m.knezevic@porta.de>
> To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
> Sent: Thursday, July 07, 2005 11:36 AM
> Subject: AW: [FileUpload] It's works under Firefox but not on IE, why ?
>
>
> if you have not specified an extra logger for the web app the output 
> should go to catalina.out. e.printStackTrace() puts everything on the 
> error output stream which also goes to catalina.out.
>
> FileItem.getName() will return different paths for ie and firefox. 
> firefox only returns the name and ie the whole path (hmmm. or the 
> other way round). there was a discussion some weeks ago about this topic.
>
> and you'll run into a little problem (which is resolvable) when you 
> move to debian. cause the file separator are different and when you 
> get a the absolute file name from the ie for the uploaded file, you 
> have to figure out on your own what belongs to the filename and what 
> to the path because of the different file separator. there was also a 
> discussion of this topic some weeks ago. just have a look at the 
> archives about that.
>
> i would try and check for item.getName() and take a look at it via 
> System.err.println(item.getName());
>
>> -----Urspr√ľngliche Nachricht-----
>> Von: Maxime [mailto:max.dev@free.fr]
>> Gesendet: Donnerstag, 7. Juli 2005 11:20
>> An: Jakarta Commons Users List
>> Betreff: Re: [FileUpload] It's works under Firefox but not on
>> IE, why ?
>>
>> Well,
>> I am working under Windows XP SP 2 for the test of servlet
>> and JSP. After
>> that , I move all the work on a server Debian station.
>> Strangely, I have no error message (I searched on TomCat
>> logs, I have found
>> nothing). Error logs can be elsewhere ?
>> I am using Netbeans 4.1 and Java 1.5.0.0_4
>>
>> Thank you.
>> Maxime
>>
>>
>> >perhaps you can describe your problem a little bit more, for
>> example: do
>> >you getting an error message, stack trace or something. on
>> what >platforms
>> >are you working windows, linux, ...
>>
>> > -----Urspr√ľngliche Nachricht-----
>> > Von: Maxime [mailto:max.dev@free.fr]
>> > Gesendet: Donnerstag, 7. Juli 2005 10:19
>> > An: commons-user@jakarta.apache.org
>> > Betreff: [FileUpload] It's works under Firefox but not on IE, why ?
>> >
>> > Hello Everybody,
>> > During 2 days, I was testing FileUpload on IE and it never
>> > work. After that, I tried on Firefox and it's works perfectly.
>> > Can you tell me why and how to resolve this problem ?
>> > It's a really pain in an ... :)
>> >
>> > Thank you.
>> > Maxime
>> >
>> >
>> >
>> > Here the form :
>> > <HTML>
>> > <HEAD>
>> > </HEAD>
>> >
>> > <BODY BGCOLOR="#FDF5E6">
>> >
>> > <h1>Upload de Fichier</h1>
>> >
>> > <form name="upload" method="post" action="/UploadFileServlet"
>> > enctype="multipart/form-data" >
>> >
>> > Upload File:<input type="file" name="source" size="30">
>> >
>> > <input type="submit" name="submitFile" value="Upload"
>> title="Upload">
>> >
>> > </form>
>> > </BODY>
>> > </HTML>
>> >
>> > Here the Servlet :
>> >
>> > import java.io.*;
>> > import java.util.*;
>> > import javax.servlet.*;
>> > import javax.servlet.http.*;
>> > import org.apache.commons.fileupload.*;
>> > import org.apache.commons.fileupload.*;
>> >
>> >
>> > public class UploadFileServlet extends HttpServlet {
>> > public void doPost(HttpServletRequest request,
>> > HttpServletResponse response)
>> > throws ServletException, IOException {
>> >
>> > System.out.println ("Uploading-Servlet");
>> >         try{
>> >                // Create a new file upload handler
>> >                DiskFileUpload upload = new DiskFileUpload();
>> >
>> >                // Set upload parameters
>> >                int  yourMaxMemorySize = 512 * 1024 * 8;
>> >                int  yourMaxRequestSize = 1024 * 1024 * 8;
>> >                String yourTempDirectory = "c:\\";
>> >
>> >                upload.setSizeThreshold(yourMaxMemorySize);
>> >                upload.setSizeMax(yourMaxRequestSize);
>> >                upload.setRepositoryPath(yourTempDirectory);
>> >
>> >                //Parse the request
>> >                List items = upload.parseRequest(request);
>> >
>> >                // Process the uploaded items
>> >                Iterator iter = items.iterator();
>> >                while (iter.hasNext()) {
>> >
>> >                    FileItem item = (FileItem) iter.next();
>> >
>> >                    //   Process a regular form field
>> >                    if (item.isFormField()) {
>> >                        String name = item.getFieldName();
>> >                        String value = item.getString();
>> >
>> >                    }
>> >                   // Process a file upload
>> >                   else {
>> >                        String fieldName = item.getFieldName();
>> >                        String fileName = item.getName();
>> >                        String contentType = item.getContentType();
>> >                        boolean isInMemory = item.isInMemory();
>> >                        File uploadedFile = new
>> > File(yourTempDirectory + fileName);
>> >                        item.write(uploadedFile);
>> >
>> >                   }
>> >                }
>> >             } catch (ServletException e) {
>> >                e.printStackTrace();
>> >             } catch (IOException e) {
>> >                e.printStackTrace();
>> >             } catch (FileUploadException e) {
>> >                e.printStackTrace();
>> >             } catch (Exception e) {
>> >                e.printStackTrace();
>> >             }
>> >
>> >    }
>> >
>> > }
>> >
>>
>> ---------------------------------------------------------------------
>> 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
>
>
>

-- 
Kind Regards
Schalk Neethling
Web Developer.Designer.Programmer.President
Volume4.Business.Solution.Developers
emotionalize.conceptualize.visualize.realize
Landlines
Tel: +27125468436
Fax: +27125468436
Web
email:schalk@volume4.com
Global: www.volume4.com
Messenger
Yahoo!: v_olume4
AOL: v0lume4
MSN: volume4_@hotmail.com

We support OpenSource
Get Firefox!- The browser reloaded - http://www.mozilla.org/products/firefox/
 
This message contains information that is considered to be sensitive or confidential and may
not be forwarded or disclosed to any other party without the permission of the sender. If
you received this message in error, please notify me immediately so that I can correct and
delete the original email. Thank you.



---------------------------------------------------------------------
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