Jakarta Commons FileUpload, error in file name extraction.

Discussion in 'Java' started by i730lover, Jul 21, 2006.

  1. i730lover

    i730lover Guest

    Scenario :
    I am using Jakarta Commons FileUpload 1.0 package, to upload files.
    I use multipart/form-data as uploading form.
    Jsp file will show info regarding uploaded files.

    Problem :
    In production server, uploaded files names are shown, with thier full
    paths,
    when internet explorer is used. I just want to extract file names only.
    To do it, I am making a new file and extracting the name.
    This works fine on windows environment, but not on linux.
    Any suggestions ?

    Testing :
    Tomcat version is 5.5.9
    JDK 1.5.0_05
    Testing on Windows XP.
    Works fine with any browser.

    Production :
    Tomcat version is 5
    JDK 1.5.0_05
    Linux OS
    Dosent work with IE


    <html>
    <head>
    <title>File Upload2</title>
    </head>

    <body>
    <h1>Welcome to upload2.</h1>

    <form action="upload2.jsp" method="post"
    enctype="multipart/form-data">
    <p><br/>
    Choose a photo to be uploaded to the server:
    <input name="myFileUpload2" type="file"/><br/>
    </p>

    <hr/>

    <p>
    <input type="submit"/>
    <input type="reset"/>
    </p>
    </form>
    </body>
    </html>











    <%@page import="org.apache.commons.fileupload.*, java.util.*,
    java.io.File, java.lang.Exception" %>

    <html>
    <head>
    <title>File Upload</title>
    </head>

    <body>
    <h1>Data Received at the Server</h1>
    <hr/>
    <p>

    <%
    if (FileUpload.isMultipartContent(request)){

    DiskFileUpload diskFileUpload = new DiskFileUpload();
    List fileItemsList = diskFileUpload.parseRequest(request);

    Iterator it = fileItemsList.iterator();
    FileItem fileItem = (FileItem)it.next();


    if (fileItem!=null){

    String fileName = fileItem.getName();
    File renamedFile = new File(
    getServletContext().getRealPath("/styles/TB/"), fileItem.getName());

    %>
    <b>Uploaded File Info:</b><br/>
    Content type: <%= fileItem.getContentType() %><br/>
    Field name: <%= fileItem.getFieldName() %><br/>
    File name: <%= fileName %><br/>
    New File name: <%= renamedFile.getName() %><br/>
    File size: <%= fileItem.getSize() %><br/><br/>
    <%
    }
    }
    %>

    </p>
    </body>
    </html>
    i730lover, Jul 21, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joshua
    Replies:
    0
    Views:
    558
    Joshua
    Oct 20, 2004
  2. Dundonald
    Replies:
    0
    Views:
    877
    Dundonald
    Mar 22, 2005
  3. Dundonald
    Replies:
    0
    Views:
    381
    Dundonald
    Mar 22, 2005
  4. Dundonald
    Replies:
    2
    Views:
    878
    Dundonald
    Mar 23, 2005
  5. Pablo
    Replies:
    2
    Views:
    425
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Nov 21, 2006
Loading...

Share This Page